• Модуль: rpa
  • Путь к файлу: ~/bitrix/modules/rpa/lib/integration/bizproc/document/item.php
  • Класс: BitrixRpaIntegrationBizprocDocumentItem
  • Вызов: Item::updateDocument
static function updateDocument($documentId, $fields, $modifiedById = null)
{
	[$typeId, $itemId] = explode(':', $documentId);

	$type = TypeTable::getById($typeId)->fetchObject();

	if (!$type)
	{
		return false;
	}

	$item = $type->getItem($itemId);

	if(!$item)
	{
		return false;
	}

	$taskId = $fields['__taskId'] ?? 0;

	if (isset($fields['STAGE_ID']) && empty($fields['STAGE_ID']))
	{
		unset($fields['STAGE_ID']);
	}

	//TODO: prepare white list, values etc.
	foreach($fields as $name => $value)
	{
		if($item->entity->hasField($name))
		{
			$item->set($name, $value);
		}
	}

	$command = Driver::getInstance()->getFactory()->getUpdateCommand($item);

	$command->setScope(ItemHistoryTable::SCOPE_AUTOMATION);
	$command->disableAllChecks();

	$command->setUserId((int)$modifiedById);

	if ($taskId)
	{
		$command->setTaskId($taskId);
		$command->setScope(ItemHistoryTable::SCOPE_TASK);
	}

	$result = $command->run();

	return $result->isSuccess();
}