How to use a set of changes for different types of fields .
Copy the link to the article
Copied

Fields in the system can be of different types and, accordingly, checking the value of fields in history will differ depending on the type of field, which is fixed for each field in the objects reference book.

Number - the numeric value of the field is checked by specifying the number to be checked, without additional characters:

changeSet.hasChangedField("delivery_cost") and changeSet.newValue("delivery_cost") == 100

String - string field types can be checked by writing the text required for to be checked in quotes, or double quotes:

changeSet.hasChangedField("status") and changeSet.newValue("status").code == "complete"
changeSet.hasChangedField("first_name") and changeSet.newValue("first_name") == "no name"

Checkbox (checkbox yes/no) - has 2 meanings: true - corresponding to the value "Yes", that is, a check mark in the field, or a clicked button. false - corresponding to the value "No", that is, there is no check mark in the field, or the button is not clicked.

changeSet.hasChangedField("call") and changeSet.newValue("call") == true

Date - to compare the value of the field to be changed with a specific date, use the date() function, the parameter of which will be the required date.

changeSet.hasChangedField("delivery_date") and changeSet.newValue("delivery_date") == date("01.01.2000")

A set of changes is an array of data, so using pipe filters you can track changes in objects nested in the array. All filters available for use are presented in the "Available filters" article.

changeSet | contains(item =>item.fieldName == "payments.status" and item.newValue.code == "paid")

The condition will be fulfilled if, at the time of the order change, in its history there is a change in the payment status to "Paid".

Points to note when tracking changes in a custom field:

Custom fields, like standard system fields, can be of different types, however, the tracking of custom fields works differently. The value the field types "Number" or "Integer" will be expressed as a number, and for other types of fields the values ​​will be expressed as text.

To track a change in a "Number" and "Integer" custom field type:

changeSet.hasChangedField("custom_integer") and changeSet.newValue("custom_integer") == 12

The condition will be fulfilled if the custom field with the character code "integer", of the "Integer" type, changes and its new value will be a number 12.

changeSet.hasChangedField("custom_number") and changeSet.newValue("custom_number") == 1.25

The condition will be fulfilled if the custom field with the symbolic code "number", with the "Number" type, changes and its new value will be a floating point number 1.25

Note

Floating point number must be specified with a dot sign

To track a change in the "Checkbox (yes/no)" custom field type:

Custom fields of type "Checkbox (yes/no)" can contain one of the following values:

true - corresponding to the value "Yes", that is, the set checkbox in the custom field. false - corresponding to the value "No", that is, an unchecked checkbox in the custom field.

Note

In the case of custom fields, "true" and "false" values must be checked as strings: ‘true’ and ‘false’ respectively.

changeSet.hasChangedField("custom_callback") and changeSet.newValue("custom_callback") == 'true'

The condition will be fulfilled if the custom field with the symbolic code "callback" of the "Checkbox (yes/no)" type changes, and its new value is the checkbox setting in this custom field.

To track a change in the "String" or "Text" custom field type:

changeSet.hasChangedField("custom_note") and changeSet.newValue("custom_note") == 'Call back till 5 pm'

The condition will be fulfilled if the custom field with the symbolic code "callback" changes, with the "String" or "Text" type, and its new value will be the text 'Call back till 5 pm'.

Important!

This condition will be fulfilled only if the field contains only information checked in the code

To track changes in an "E-mail" type custom field:

changeSet.hasChangedField("custom_mail") and changeSet.newValue("custom_mail") == "support@retailcrm.pro"

The condition will be fulfilled if the custom field with the character code "mail" changes, with the "E-mail" type and its new value will be support@retailcrm.pro

Note

In the system interface, fields with this type are validated for the correctness of the data entered in the field, using the mask mail@site.pro. The required sign is @ and the url address after this sign.

To track changes in the "Data book" custom field type:

The new or old value of a "Data book" field type stores the symbolic code of the corresponding data book in text format

changeSet.hasChangedField("custom_directory") and changeSet.newValue("custom_directory") == "two"

The condition will be fulfilled if the custom field with the symbolic code "directory" changes, with the type "Data book" and its new value will be with the symbolic code "two" of the element of the data book.

To track changes in the "Date" custom field type: in the format

changeSet.hasChangedField("custom_birthday") and changeSet.newValue("custom_birthday") == "1980-01-13"

Important!

In "Date" type custom fields, the data in the tracking history is stored in the YYYY-MM-DD format, which is different from the format in the system interface - DD.MM.YYYY

The condition will be fulfilled if the custom field with the symbolic code "birthday" changes with the type "Date" and its new value will be 13.01.1980.

Thank you for your feedback.
Was this article helpful?
No
  • Рекомендации не помогли
  • Нет ответа на мой вопрос
  • Текст трудно понять
  • Не нравится описанный функционал
Yes
Previous article
Set of changes
The article describes how to work with a set of changes.