Как изменить номера телефонов и e-mail на примере контакта
Описание
Примеры добавления/изменения/удаления телефона и e-mail на примере контакта.
Внимание! Для использования примера настройте работу класса CRest и подключите файл crest.php в файлах, где используется данный класс. Подробнее.
Работа с E-Mail
$sEmail1 = rand(111111111, 999999999) . '@nomail.com'; $sEmail2 = rand(111111111, 999999999) . '@nomail.com'; $arNewEmail = [ [ 'VALUE' => $sEmail1, 'VALUE_TYPE' => 'HOME' ], [ 'VALUE' => $sEmail2, 'VALUE_TYPE' => 'HOME' ] ]; //create contact with phone $newContact = CRest::call( 'crm.contact.add', [ 'fields' => [ 'NAME' => 'CHANGE EMAIL', 'EMAIL' => $arNewEmail ] ] ); if ($newContact['result'] > 0) { //get contact with email $newContactData = CRest::call( 'crm.contact.get', [ 'id' => $newContact['result'] ] ); //change 1 email and delete 2 email if (!empty($newContactData['result']['EMAIL'][0]) && !empty($newContactData['result']['EMAIL'][1])) { $arUpdateEmail = [ [//change 'ID' => $newContactData['result']['EMAIL'][0]['ID'], 'VALUE' => rand(111111111, 999999999) . '@nomail.com' ], [//delete 'ID' => $newContactData['result']['EMAIL'][1]['ID'], 'VALUE' => ''//empty value for delete email ], ]; $resultContactChange = CRest::call( 'crm.contact.update', [ 'id' => $newContactData['result']['ID'], 'fields' => [ 'EMAIL' => $arUpdateEmail ] ] ); } } else { echo 'error creat contact ' . $newContact['error_description']; }
Работа с телефонами
$sPhone1 = rand(111111111, 999999999); $sPhone2 = rand(111111111, 999999999); $arNewPhone = [ [ 'VALUE' => $sPhone1, 'VALUE_TYPE' => 'HOME' ], [ 'VALUE' => $sPhone2, 'VALUE_TYPE' => 'HOME' ] ]; //creat contact with phone $newContact = CRest::call( 'crm.contact.add', [ 'fields' => [ 'NAME' => 'CHANGE PHONE', 'PHONE' => $arNewPhone ] ] ); if ($newContact['result'] > 0) { //get contact with phone $newContactData = CRest::call( 'crm.contact.get', [ 'id' => $newContact['result'] ] ); //change 1 phone and delete 2 phone if (!empty($newContactData['result']['PHONE'][0]) && !empty($newContactData['result']['PHONE'][1])) { $arUpdatePhone = [ [//change 'ID' => $newContactData['result']['PHONE'][0]['ID'], 'VALUE' => rand(111111111, 999999999) ], [//delete 'ID' => $newContactData['result']['PHONE'][1]['ID'], 'VALUE' => ''//empty value for delete phone ], ]; $resultContactChange = CRest::call( 'crm.contact.update', [ 'id' => $newContactData['result']['ID'], 'fields' => [ 'PHONE' => $arUpdatePhone ] ] ); } } else { echo 'error creat contact ' . $newContact['error_description']; }
© «Битрикс», 2001-2024, «1С-Битрикс», 2024