A
A
Ainur Shakirov2022-03-26 19:10:08
1C-Bitrix
Ainur Shakirov, 2022-03-26 19:10:08

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);
}


And the handler does not work, the function does not start. What's wrong?...
Leads are added like this:

$obLead = new CCrmLead(false);
    $ID = $obLead->Add($arLead, true, array("REGISTER_SONET_EVENT" => true, "DISABLE_USER_FIELD_CHECK" => true));


Everything seems to be in the docks, but it doesn't work...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2022-04-09
@gromdron

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)
);

The file has been created.
Check the rights to the folder where you write the file and check if the crm module is connected on the page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question