Add
int CIBlockElement::Add( array arFields, bool bWorkFlow = false, bool bUpdateSearch = true );Adds a new element to an information block.
Parameters
Parameter | Description |
---|---|
arFields | An array of the format Array("field"=>"value", ...)
containing values of the element
fields of an information block. May also contain the field PROPERTY_VALUES,
which is an array of the element properties in the format Array("property
code"=>"value"). The property code can be
either numeric or mnemonic property code. For more information on properties, see CIBlockElement::SetPropertyValues() and CIBlockElement::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
The method returns the ID of the added element on success. In case of failure returns false and sets the property LAST_ERROR to the error description text.See Also
Example
<? $el = new CIBlockElement; $PROP = array(); $PROP[12] = "White"; // property with code 12 is assigned value "White" $PROP[3] = 38; // property with code 3 is assigned value 38 $arLoadProductArray = Array( "MODIFIED_BY" => $USER->GetID(), // element modified by the current user "IBLOCK_SECTION" => false, // put element 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") ); if($PRODUCT_ID = $el->Add($arLoadProductArray)) echo "New ID: ".$PRODUCT_ID; else echo "Error: ".$el->LAST_ERROR; ?>
© «Bitrix24», 2001-2024