A
A
Alexander2021-02-26 12:48:50
1C-Bitrix
Alexander, 2021-02-26 12:48:50

How to add transaction change event handling in the Bitrix24 box?

The task is: when changing a deal, get a custom field and fill in another custom field based on its data.

In /local/php_interface/init.php I write the following code:

AddEventHandler("crm", "OnAfterCrmDealUpdate", "OnAfterCrmDealUpdateHandler");
function OnAfterCrmDealUpdateHandler(&$arFields)
{
  $log  = "\n------------------------\n";
  $log .= date("Y.m.d G:i:s") . "\n";
  $log .= print_r($arFields, 1);
  $log .= "\n------------------------\n";
  file_put_contents( $_SERVER["DOCUMENT_ROOT"].'/local/php_interface/result.log', $log, FILE_APPEND);

  return true;
}


But no data is written to the log.
How can I catch this event correctly? I did not find anything in the documentation examples.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2021-02-26
@gromdron

Try using the new EventManager entry:

<?php

$eventManager = \Bitrix\Main\EventManager::getInstance();

$eventManager->addEventHandlerCompatible(
  'crm',
  'OnAfterCrmDealUpdate',
  function (&$arFields){

    ob_start();
    echo PHP_EOL."<pre>".PHP_EOL;
    var_dump($arFields);
    file_put_contents(__DIR__.'/log.log', ob_get_clean(), FILE_APPEND);
  }
);

G
Guliver99, 2021-04-16
@Guliver99

check the rights to change the logged file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question