• Модуль: rpa
  • Путь к файлу: ~/bitrix/modules/rpa/lib/controller/task.php
  • Класс: BitrixRpaControllerTask
  • Вызов: Task::addUserAction
public function addUserAction($typeId, $stageId, $robotName, string $userValue)
{
	$updatedRobot = null;
	$documentType = BitrixRpaIntegrationBizprocDocumentItem::makeComplexType($typeId);

	$errors = [];
	$user = current(CBPHelper::UsersStringToArray($userValue, $documentType, $errors));

	if (!$user)
	{
		return false;
	}

	$template = new BitrixBizprocAutomationEngineTemplate($documentType, $stageId);
	$robots = [];

	foreach ($template->getRobots() as $robot)
	{
		if ($robotName === $robot->getName())
		{
			$robotUsers = $robot->getProperty('Responsible');
			if (!in_array($user, $robotUsers))
			{
				$robotUsers[] = $user;
				$robot->setProperty('Responsible', $robotUsers);
				$updatedRobot = $robot;
			}
		}
		$robots[] = $robot;
	}

	if($updatedRobot)
	{
		$tplUser = new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser);
		$result = $template->save($robots, $tplUser->getId());

		if($result->isSuccess())
		{
			Driver::getInstance()->getTaskManager()->onTaskPropertiesChanged(
				$template->getDocumentType(),
				$template->getId(),
				$updatedRobot->toArray()
			);

			Driver::getInstance()->getPullManager()->sendRobotUpdatedEvent($typeId, $stageId, ['robotName' => $robotName]);
		}
	}

	return true;
}