Item::UpdateDocument

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Item
  4. UpdateDocument
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integration/bizproc/document/item.php
  • Класс: Bitrix\Crm\Integration\BizProc\Document\Item
  • Вызов: Item::UpdateDocument
static function UpdateDocument($documentId, $fields, $modifiedBy = null)
{
	$documentInfo = static::GetDocumentInfo($documentId);
	if (!$documentInfo)
	{
		throw new ArgumentNullException('documentId');
	}
	if (!is_int($modifiedBy))
	{
		$modifiedBy = 0;
	}
	[$entityTypeId, $entityId] = [$documentInfo['TYPE_ID'], $documentInfo['ID']];

	$factory = Container::getInstance()->getFactory($entityTypeId);
	$item = isset($factory) ? $factory->getItem($entityId) : null;

	if (is_null($item))
	{
		$errorMessage = Loc::getMessage('CRM_ENTITY_EXISTENCE_ERROR', ['#DOCUMENT_ID#', $documentId]);
		throw new ArgumentException($errorMessage);
	}

	$fieldCaster = new Crm\Automation\Fields\ItemFieldsCaster($item, static::getEntityFields($entityTypeId));
	$item->setFromCompatibleData($fieldCaster->externalize($fields));

	$updateOperation = $factory->getUpdateOperation($item, static::getContext($modifiedBy));

	$result = static::launchOperation($updateOperation);
	$errorMessages = $result->getErrorMessages();

	return $result->isSuccess() ?: end($errorMessages);
}

Добавить комментарий