-
-
Save gromdron/a8d93931548936f55fc5786f6b111698 to your computer and use it in GitHub Desktop.
Create task from template with correct checklist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \Bitrix\Main; | |
use \Bitrix\Tasks; | |
/** | |
* Template id | |
* @var int | |
*/ | |
$templateId = 1; | |
/** | |
* User id | |
* @var int | |
*/ | |
$userId = 1; | |
try | |
{ | |
if ( ! Main\Loader::IncludeModule('tasks') ) | |
{ | |
throw new \Exception("Task module not included"); | |
} | |
$replicator = new Tasks\Util\Replicator\Task\FromTemplate(); | |
$replicator->setConfig('DISABLE_SOURCE_ACCESS_CONTROLLER', true); | |
$produceResult = $replicator->produce( | |
$templateId, | |
$userId, | |
array( | |
'OVERRIDE_DATA' => array( | |
'CREATED_DATE' => new Main\Type\DateTime | |
) | |
) | |
); | |
if ( !$produceResult->isSuccess() ) | |
{ | |
throw new \Exception("Reproduce error: ".implode(', ', $produceResult->getErrorMessages())); | |
} | |
$task = $produceResult->getInstance(); | |
/** | |
* Created task id -> $task->getId() | |
*/ | |
} | |
catch( \Exception $e ) | |
{ | |
/** | |
* @todo Log task | |
* $e->getMessage() | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Что бы у созданных задач отрабатывали настроенные роботы:
$task = $res->getInstance();
\Bitrix\Tasks\Integration\Bizproc\Listener::onTaskAdd($task->getId(), $task->getData());