Bitrix Site Manager

CIBlockElement::Update

bool
CIBlockElement::Update(
 int ID,
 array arFields,
 bool bWorkFlow = false,
 bool bUpdateSearch = true
);

The method updates parameters (fields) of an element.

Parameters

ParameterDescription
ID Element ID.
arFields An array of the format Array("field"=>"value", ...) containing values of the element fields.

Additionally, it can contain the field PROPERTY_VALUES which is an array with pairs "property code"=>"value" where the property code is the numeric or mnemonic property identifier, and the value is a single value or an array of values for multiple-value properties. Please note that the PROPERTY_VALUES array must contain a full set of properties and values; in case any currently existing property is missing from this array, all its values are removed from the element property set.

The following methods also sets property values: SetPropertyValues, SetPropertyValueCode.
bWorkFlow If true, the new element is added in the workflow mode. If the Workflow module is installed, this operation is journalled in the element log.

Optional. By default, elements are added without the workflow features.
bUpdateSearch Tells to index the new element in the search engine. To speed up processing when adding a large set of elements, set this parameter to false and re-index the search database later. Optional.

Return Values

Returns true on success or false otherwise. In the latter case, the LAST_ERROR property of the instance contains the error description.

See Also

  • CIBlockElement::Add

    Example


    <?
    $el = new CIBlockElement;
    
    $PROP = array();
    $PROP[12] = "White";  // assign the value of "White" to the property with the ID of 2
    $PROP[3] = 38;        // assign the value of 38 to the property with the ID of 3
    
    $arLoadProductArray = Array(
      "MODIFIED_BY"    => $USER->GetID(), // element is modified by the current user
      "IBLOCK_SECTION" => false,          // element resides in the root
      "IBLOCK_ID"      => 18,
      "PROPERTY_VALUES"=> $PROP,
      "NAME"           => "element",
      "ACTIVE"         => "Y",            // active
      "PREVIEW_TEXT"   => "brief text",
      "DETAIL_TEXT"    => "detailed text",
      "DETAIL_PICTURE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/image.gif")
      );
    
    $PRODUCT_ID = 2;  // modify element with the ID of 2
    $res = $el->Update($PRODUCT_ID, $arLoadProductArray);
    ?>