retailCRM Documentation

Validation

Validation is intended to create additional checking of order or customer changes, which is done by system user. These checks are applied both in order/customer editing and in group operations.

In the condition there is specified a logical expression, which will cancel the action if it is true, and the user will get an error message.

In the condition you may work with object, on which the action is carried out (it is order or customer), and also with object changeSet (type Change\EntityChangeSet), which contains information on alterable fields. You may read more about changeSet.

In several cases in validation is required check some attributes of user, who changes data in order/customer. For example, to check if the user is in definite group. You can get user, who changed the data, through the function user().

Examples

1. Deny change the order payment status

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

2. Delivery date must be today's date or later

order.getDeliveryDate() < date('now 00:00:00') and (
    (changeSet.isCreate() and order.getDeliveryDate()) or
    (changeSet.isUpdate() and changeSet.hasChangedField('delivery_date'))
)

3. Shipment can only be carried out by the user in group Logistics

Note By default in system there is no group Logistics, but you can create necessary users groups.

changeSet.hasChangedField('shipped') and not user().hasGroup('logist')

4. User can only change certain fields

changeSet.hasChangesExcluding(['status', 'first_name', 'last_name'])

PrintEditHistory
Page last modified on October 23, 2017, at 02:21 PM