Skip to content

Instantly share code, notes, and snippets.

@gromdron
Last active March 15, 2023 12:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gromdron/a8d93931548936f55fc5786f6b111698 to your computer and use it in GitHub Desktop.
Save gromdron/a8d93931548936f55fc5786f6b111698 to your computer and use it in GitHub Desktop.
Create task from template with correct checklist
<?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()
*/
}
@lycifep
Copy link

lycifep commented Mar 15, 2023

Что бы у созданных задач отрабатывали настроенные роботы:
$task = $res->getInstance();
\Bitrix\Tasks\Integration\Bizproc\Listener::onTaskAdd($task->getId(), $task->getData());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment