Points to note when forming a validation
Copy the link to the article
Copied

Validation is intended to create additional checks for changes to orders/customers/corporate customers/tasks that the user makes in the system. Checks are applied not only when editing a card of order/customer/corporate customer/task, but also in group operations.

The condition specifies a Boolean expression, if true, the action will be canceled, and the user will receive an error message.

In a condition, you can work with the object being acted upon (they are order, customer, customercorporate, task), as well as with the changeSet object (type Change\EntityChangeSet), which contains information about mutable fields.

changeSet.isUpdate() and changeSet.hasChangedField('payments.status')

In some cases, validation requires checking some attributes of the user who changes data in the order/customer/corporate customer/task. For example, checking that a user belongs to a specific group. You can get the user who changes the data via the user() function.

  • Prohibition of completing a task without the “Description” field filled in
changeSet.isUpdate()
and changeSet.hasChangedField("complete")
and changeSet.getNewValue("complete") == true
and task.commentary == null
  • Prohibition on creating a task without a due date
changeSet.isCreate() and task.getDatetime() == null
  • Only task completion is allowed, editing is not allowed
changeSet.isUpdate()
and changeSet.hasChangesExcluding(["complete", "completed_at"])
  • Prohibition to change the payment status of the order
changeSet.isUpdate() and changeSet.hasChangedField('payments.status')
  • Delivery date must be today or later
order.deliveryDate < date('now 00:00:00') and (
(changeSet.isCreate() and order.deliveryDate) or
(changeSet.isUpdate() and changeSet.hasChangedField('delivery_date'))
)
  • Only the user of the "Logistician" group can carry out the shipment.

Note

By default, there is no "Logistician" group in the system, but you can create the user groups you need.

changeSet.hasChangedField('shipped') and not user().hasGroup('logist')
  • User can change only certain fields
changeSet.hasChangesExcluding(['status', 'first_name', 'last_name'])
Thank you for your feedback.
Was this article helpful?
No
  • Рекомендации не помогли
  • Нет ответа на мой вопрос
  • Текст трудно понять
  • Не нравится описанный функционал
Yes
Previous article
Working with products in triggers, validations and price types
Order details are an array of data, therefore, working with them is conducted using special filters created in PipeLanguage. In this article, we will analyse how to work with filters in price types, triggers and validation and in the context of products.
Next article
Checking the executions of triggers and validation
If you need to check a trigger or validation for correct functioning, you can use the actions log, which displays each execution and, if it occurs, an error with a detailed description.
#}