Views: 11558 (Data available since 06.02.2017)

This action permits you to execute an arbitrary PHP code. Attention! Only a user with administrator’s access permissions can set PHP code


Attention! 1. This action is only available in Bitrix24 Self-hosted version.

Note: The code must be indicated with no opening or closing tags (<?, ?>).

Action Parameters

Since the meaning of most fields is clear from their names, their description is omitted.


Examples of application

Note: Code must be specified without opening and closing tags (<?, ?>).

Important! It is not recommended to use expressions like {=...} in the code boy. They can contain parameters that can be modified by any user of bitrix24 account without necessary access permissions.
For example, instead of structure {=Variable:COMPANY_NAME} use code>$root->GetVariable('COMPANY_NAME').

Setting a value for the variable

$this->SetVariable('Variable1', 12345);

where:

Variable1 – identifier of the variable to which a value will be assigned (12345 number).

Entering several users to the User type variable

$this->SetVariable("user", array("user_1", "user_2"));

where:

array("user_1", "user_2") – an array of users in the format user_[user_identifier_in_the_system].

The use of PHP code and values of fields/variables to obtain the name of the infoblock element

$arFilter = Array("IBLOCK_ID" => {=Variable:Variable1_printable}, "ID" => {=Document:PROPERTY_1}); 
$dc = CIBlockElement::GetList(array(), $arFilter, array("NAME"));
$br = $dc->Fetch();
$Pbrr = $br["NAME"];
$this -> SetVariable('Variable2', $Pbrr);

where:

{=Variable:Variable1_printable} – value of the variable containing the infoblock identifier;
{=Document:PROPERTY_1} – field of the document containing the infoblock element identifier;
Variable2 – identifier of the variable which will be assigned the calculated name of the infoblock element.

Conversion of the document field format and its further use

Let us consider an example of conversion of the document field User to an understandable form in order to use it when sending a message:

  1. A variable to store the converted value of the document field should be created in the business process template;
  2. Let us indicate the following in the PHP code action:
    $rsUser = CUser::GetByID({=Document:PROPERTY_USER});
    $arUser = $rsUser->Fetch();
    $this->SetVariable('#Variable_name#', $arUser[NAME].' '.$arUser[SECOND_NAME].' '.$arUser[LAST_NAME]);
    
  3. After that, we have to use the result of this variable instead of the document field in the block used for notification.



Courses developed by «Bitrix», Inc.