• Модуль: bizproc
  • Путь к файлу: ~/bitrix/modules/bizproc/lib/controller/globalfield.php
  • Класс: BitrixBizprocControllerGlobalField
  • Вызов: GlobalField::upsertVariable
private function upsertVariable($variableId, $property, $documentType): array
{
	$userId = (int)($this->getCurrentUser()->getId());
	$canUpsert = BitrixBizprocWorkflowTypeGlobalVar::canUserUpsert($documentType, $userId);
	if (!$canUpsert)
	{
		return [
			'error' => BitrixMainLocalizationLoc::getMessage(
				'BIZPROC_CONTROLLER_GLOBALFIELD_CANT_UPSERT_VARIABLE_RIGHT'
			),
		];
	}

	$error = [];
	$value = $this->getDefaultValue($documentType, $property, $error);
	if ($error)
	{
		return ['error' => $error[0]['message']];
	}
	$property['Default'] = $value ?? '';
	$property['Name'] = trim($property['Name']);

	$userId = (int)($this->getCurrentUser()->getId());
	$result = BitrixBizprocWorkflowTypeGlobalVar::upsertByProperty($variableId, $property, $userId);
	if (!$result->isSuccess())
	{
		return [
			'error' => $result->getErrorMessages()[0],
		];
	}

	return ['status' => 'success'];
}