Answer the question
In order to leave comments, you need to log in
How to remove one value of a multiple property in BITRIX using api?
there is a multiple property HIT
Values
In the product
I can’t give the CIBlockElement::SetPropertyValues function the right
way
CIBlockElement::SetPropertyValues($arResult["ID"], $arResult["IBLOCK_ID"], ['2141' => false], "HIT");
Answer the question
In order to leave comments, you need to log in
How trivial the task sounds...
Reality:
\Bitrix\Main\Loader::includeModule('iblock');
$propertyValuesIdByXmlId = $elementPropertyValuesById = [];
$iblockId = 17;
$elementId = 176;
$propertyCode = 'HIT';
$deletePropertyValuesXmlId = ['NEW'];
$iterator = \Bitrix\Iblock\PropertyEnumerationTable::getList([
'select' => ['*'],
'filter' => ['PROPERTY.IBLOCK_ID' => $iblockId, 'PROPERTY.CODE' => $propertyCode]
]);
while($row = $iterator->fetch()) {
$propertyValuesIdByXmlId[$row['XML_ID']] = $row['ID'];
}
$dbRes = CIBlockElement::GetList([], ['IBLOCK_ID' => $iblockId, 'ID' => $elementId], false, false, ['IBLOCK_ID', 'ID', 'PROPERTY_'.$propertyCode]);
while($arRes = $dbRes->Fetch()) {
$value = $arRes['PROPERTY_'.$propertyCode.'_VALUE'];
$valueId = $arRes['PROPERTY_'.$propertyCode.'_ENUM_ID'];
$elementPropertyValuesById[$valueId] = $value;
}
if($elementPropertyValuesById) {
foreach($deletePropertyValuesXmlId as $xmlId) {
$deletePropertyValueId = $propertyValuesIdByXmlId[$xmlId];
if(isset($elementPropertyValuesById[$deletePropertyValueId])) {
unset($elementPropertyValuesById[$deletePropertyValueId]);
}
}
CIBlockElement::SetPropertyValuesEx($elementId, $iblockId, [$propertyCode => array_keys($elementPropertyValuesById)]);
}
In your case you need to use SetPropertyValuesEx
The method saves the values of all properties of the information block element. Unlike SetPropertyValues, it may not contain the full set of values. Property values not specified in the PROPERTY_VALUES array will be preserved. This method is more economical in the number of database queries. The method is static.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question