• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/automation/engine/runtime.php
  • Класс: Bitrix\Crm\Automation\Engine\Runtime
  • Вызов: Runtime::runTemplates
protected function runTemplates($documentStatus)
{
	if (!Automation\Helper::isBizprocEnabled())
		return false;

	$iterator = Entity\TemplateTable::getList(array(
		'filter' => array(
			'=ENTITY_TYPE_ID' => $this->getTarget()->getEntityTypeId(),
			'=ENTITY_STATUS'  => $documentStatus
		)
	));
	$templateData = $iterator->fetch(); // single, yet (?)

	if ($templateData)
	{
		$template = new Template($templateData);

		$errors = array();
		$trigger = $this->getTarget()->getAppliedTrigger();

		if (!$template->isExternalModified() && !$trigger && !$template->getRobots())
		{
			return false;
		}

		$workflowId = \CBPDocument::StartWorkflow(
			$templateData['TEMPLATE_ID'],
			$this->getBizprocDocumentId(),
			array(
				\CBPDocument::PARAM_USE_FORCED_TRACKING => !$template->isExternalModified(),
				\CBPDocument::PARAM_IGNORE_SIMULTANEOUS_PROCESSES_LIMIT => true
			),
			$errors
		);

		if (!$errors && $trigger && $workflowId)
		{
			$this->writeTriggerTracking($workflowId, $trigger);
		}

		$this->setStarted($this->getTarget()->getEntityId(), $documentStatus);
	}
	return true;
}