CCrmLeadWS::Add

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmLeadWS
  4. Add
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/ws_lead.php
  • Класс: \CCrmLeadWS
  • Вызов: CCrmLeadWS::Add
public function Add($data)
{
	global $DB;
	if (($r = self::CheckAuth()) !== false)
		return $r;

	$arFieldsInfo = CCrmLead::GetFields();

	$arFields = array();
	$arEl = $data->elementsByName('Field');
	foreach ($arEl as $child)
	{
		$children = $child->children();
		$sFieldName = $child->getAttribute('id');

		// Fix for issue #40193
		if(!isset($arFieldsInfo[$sFieldName]))
		{
			continue;
		}

		if (!is_null($children))
		{
			$arFields[$sFieldName] = array();
			foreach ($children as $child)
				$arFields[$sFieldName][]  = $child->content;
		}
		else
			$arFields[$sFieldName]  = $child->content;
	}

	CCrmFieldMulti::PrepareFields($arFields);
	$CCrmUserType = new CCrmUserType($GLOBALS['USER_FIELD_MANAGER'], CCrmLead::$sUFEntityID);
	$CCrmUserType->InternalizeFields($arFields, ',');

	$CCrmBizProc = new CCrmBizProc('LEAD');
	if (false === $CCrmBizProc->CheckFields(false, true))
		return new CSoapFault('CCrmLead::Add Bizproc', htmlspecialcharsbx(strip_tags(nl2br($CCrmBizProc->LAST_ERROR))));

	$CCrmLead = new CCrmLead();
	$DB->StartTransaction();
	$ID = $CCrmLead->Add($arFields);
	if ($ID !== false && !$CCrmBizProc->StartWorkflow($ID))
	{
		$DB->Rollback();
		return new CSoapFault('CCrmLead::Add Bizproc', htmlspecialcharsbx(strip_tags(nl2br($CCrmBizProc->LAST_ERROR))));
	}

	if ($ID === false)
	{
		$DB->Rollback();
		return new CSoapFault('CCrmLead::Add', htmlspecialcharsbx(strip_tags(nl2br($arFields['RESULT_MESSAGE']))));
	}

	$DB->Commit();
	return 'ok';
}

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