Views: 13163
Last Modified: 10.10.2024

Let us consider an example when the values from the user’s list boxes will be recorded into the user’s properties of an infoblock using a business process.

In this case, after the list boxes Name, String, and File (several files) are filled in and subsequently saved, a new element will be created in a relevant infoblock. The user’s properties of such infoblock will contain the values of the list boxes indicated above. The name of this element will correspond to the name of the created list element.


  • To begin with, let us create additional boxes in the list:

    Values of these boxes will be recorded in the user’s properties of the infoblock using a business process.

    Set a default value for the box IBlock ID to avoid filling it in each time when we create a new element of the list (in our case it will be an infoblock with ID = 1). This box is created for demonstration purposes only.

    Note: The infoblock ID can also be written directly in the code (see below) or variable of a business process.

  • Go to the infoblock.

    Go to the infoblock settings page, tab Properties (Control Panel > Content > Information blocks > Information block type > required_iblock) and create new user’s properties to which values from the list boxes will be recorded.

  • Go to the business process proper. Let us create a template of a sequential business process.
  • Create 2 variables to be used for adjustment purposes:

    • ELEMENT_ID - a business process variable to which the ID of the created infoblock element will be recorded in case of success,
    • ERROR - a business process variable to which the error text will be recorded in case of failure in creating an infoblock element.

  • Let us take a code from the sample API query CIBlockElement::Add

    Source code

    and modify it:

    <?
    CModule::IncludeModule("iblock"); //connect the module of infoblocks
    
    $el = new CIBlockElement;
    
    $PROP = array();
    $PROP[IB_CUSTOM_PROPERTY] = {=Document:PROPERTY_106};
    // set for the infoblock property "IB_CUSTOM_PROPERTY" of the type "string" a value from the document box "PROPERTY_106"  
    
    $files = explode(', ',"{=Document:PROPERTY_107}");
    foreach($files as $key=>$value)
     {
      $PROP[IB_FILE_PROPERTY]['n'.$key]=array('VALUE'=> CFile::MakeFileArray($value), 'DESCRIPTION' => '');
     }  
    // create for the infoblock property "IB_FILE_PROPERTY" of the type "file" a (multiple) value from the document box "PROPERTY_107"	
    	
    $arLoadProductArray = Array(
      "IBLOCK_ID" = >{=Document:PROPERTY_108},	
    // set the  Infoblock ID> where the element will be created from the document box "PROPERTY_108" of the type "string" 	
      "NAME" => {=Document:NAME},
    // set the Name of the created infoblock element from the document box "Name"	
     "PROPERTY_VALUES"	=> $PROP,
    );
    
    $ELEMENT_ID = $el->Add($arLoadProductArray);
    
    if($ELEMENT_ID > 0)
     $this->SetVariable('ELEMENT_ID', $ELEMENT_ID);
    // set a value containing the number of the created infoblock element (should such infoblock element be created) for the business process
    // variable "ELEMENT_ID" 
    else
     $this->SetVariable('ERROR', $el->LAST_ERROR);
    // set a value containing the text of the error message (should the infoblock element be not created) for the business process variable "ERROR"	
    ?>
    

    This code will create (using API methods) a new infoblock element where the user’s properties IB_CUSTOM_PROPERTY, IB_FILE_PROPERTY, and also the infoblock element name will contain values of user’s boxes PROPERTY_106, PROPERTY_107, PROPERTY_108, and the value of the box list element name.

    After that, we will add to the template the activity PHP Code where we will indicate our changed code.

  • We will add to the template the activity Log entry indicating the following text:
    {=Variable:ELEMENT_ID_printable}, {=Variable:ERROR_printable}

    This way, we will record the value of debugging variables into the business process execution report for analysis in case of errors.




Courses developed by Bitrix24