N
N
Nikolai Pinevich2020-01-16 13:27:31
Bitrix24
Nikolai Pinevich, 2020-01-16 13:27:31

How to run a business process in Bitrix 24 to change a specific field?

There is a field of type "List" for a contact in Bitrix24, how to start a business process only when this field is changed?
Example: a manager came into contact and changed the value in the "Customer group" list from "Group 1" to "Group 2".
When the contact is saved, the workflow should fire. And so that when changing other fields in the contact, this business process does not start.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Ermilichev, 2020-02-05
@Masas

private static $isFieldChanged = false;
 
/**
 * Событие перед обновлением контакта
 **/
public static function handleOnBeforeContactUpdae(&$fields)
{
  //Если поле присутствует в массиве обновления
  if(array_key_exists('UF_CODE', $fields))
  {
    //Проверяем его текущее значение
    $currentContact = \Bitrix\Crm\ContactTable::getRow([
      'filter' => [
        'ID' => $fields['ID']
      ],
      'select' => ['UF_CODE']
    ]);
    
    if($currentContact['UF_CODE'] != $fields['UF_CODE'])
    {
      static::$isFieldChanged = true;
    }
    
  }
}

/**
 * Событие после обновления контакта
 **/
public static function handleOnAfterContactUpdae(&$fields)
{
  if(static::$isFieldChanged === true)
  {
    static::$isFieldChanged = false;
    // Запускаем наш бизнес-процесс
    ...
  }
}

A
Alexander, 2020-09-30
@cudu

I work in the cloud version, so in my case I go from the opposite: I close all fields for changes and create a process (s) for changing the document. Suppose, in your case, create a separate process for changing the Group field (and maybe add other fields that you would like to change in this way).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question