A
A
Alexander Ivanov2018-02-14 13:13:09
1C-Bitrix
Alexander Ivanov, 2018-02-14 13:13:09

Why doesn't the handler fire when the event is caught?

There is an event handler when creating an infoblock in init.php

<?php
// регистрация обработчика в /bitrix/php_interface/init.php
AddEventHandler(12, "OnAfterIBlockElementAdd", "admissionToReferal");
$result = admissionToReferal($arFields);
if($result){echo 'Функция сработала';}
else echo 'Функция не сработала';

function admissionToReferal($arFieldsParam)
{
     if($arFieldsParam["ID"]>0){
   //событие при добавлении блока Платёж
   $payId = $arFieldsParam["ID"];
   
   
   $arSelect = Array("ID", "SEND");
         $arFilter = Array("IBLOCK_ID"=>12, "ID"=>$payId);
   $res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
   
    while($ob = $res->GetNextElement()){ 
         $arFields = $ob->GetFields(); 
   $arProps = $ob->GetProperties(); 
          print_r($arFields);
    print_r($arProps);
          }     
        }
}
?>

after creating the infoblock, the function should work, but the string "The function did not work" is returned to me. Where did I go wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Epifanov, 2018-02-14
@kacheleff

your admissionToReferal function does not return any result (i.e. returns NULL), because of this, the line "The function did not work" is displayed.
However, this does not mean that the function failed.
Call die() in the body of the function and see if it worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question