Answer the question
In order to leave comments, you need to log in
How to make the Bitrix event handler work?
Here is the code in init.php
<?
AddEventHandler("crm", "OnBeforeCrmLeadAdd", "CheckOnBeforeCrmLeadAdd");
AddEventHandler("crm", "OnAfterCrmLeadAdd", "CheckOnBeforeCrmLeadAdd");
AddEventHandler("crm", "OnAfterExternalCrmLeadAdd", "CheckOnBeforeCrmLeadAdd");
function CheckOnBeforeCrmLeadAdd(&$arFields) {
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/log_lead.log",print_r($arFields,true)."\n",FILE_APPEND);
}
$obLead = new CCrmLead(false);
$ID = $obLead->Add($arLead, true, array("REGISTER_SONET_EVENT" => true, "DISABLE_USER_FIELD_CHECK" => true));
Answer the question
In order to leave comments, you need to log in
Need more context.
I have now put the following code in the PHP console:
AddEventHandler("crm", "OnBeforeCrmLeadAdd", "CheckOnBeforeCrmLeadAdd");
AddEventHandler("crm", "OnAfterCrmLeadAdd", "CheckOnBeforeCrmLeadAdd");
AddEventHandler("crm", "OnAfterExternalCrmLeadAdd", "CheckOnBeforeCrmLeadAdd");
function CheckOnBeforeCrmLeadAdd(&$arFields) {
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/log_lead.log",print_r($arFields,true)."\n",FILE_APPEND);
}
\Bitrix\Main\Loader::IncludeModule('crm');
$obLead = new \CCrmLead(false);
$ID = $obLead->Add(
$leadfields = ['TITLE'=>'test'],
true,
array("REGISTER_SONET_EVENT" => true, "DISABLE_USER_FIELD_CHECK" => true)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question