documentation.lsfusion.org will be shutting down soon, use https://docs.lsfusion.org instead please.
The CONSTRAINT instruction creates a constraint.
The CONSTRAINT instruction creates a constraint. If the constraint is violated, the user will be shown the message defined in the instruction.
Also, by using the CHECKED option you can use the constraint when showing dialogs for changing properties whose values may violate the constraint if changed. In this instance an additional filter will be set in the dialog so that, when the property value changes, the constraint is not violated. If it is necessary to limit the set of properties for which the above filtering will be performed, the list of properties can be specified after the keyword BY .
Creating a constraint is pretty similar to the following instruction:
but it also has a number of advantages.
An expression whose value is a condition for the constraint being created. If the obtained property does not contain the PREV operator, the platform automatically wraps it into the SEToperator.
propertyId1, ..., propertyIdN
List of property IDs. When showing change dialog for each property in that list, options that violate the created constraint will be filtered.
An expression whose value is shown as a message to the user when the set constraint is violated. It may be either a string literal or a property without parameters.
// balance not less than 0
CONSTRAINT balance(Sku s, Stock st) < 0
MESSAGE 'The balance cannot be negative for ' + (GROUP CONCAT 'Product: ' + name(Sku ss) + ' Warehouse: ' + name(Stock sst), '\n' IF SET(balance(ss, sst) < 0));
barcode = DATA STRING (Sku);
// "emulation" security policy
CONSTRAINT DROPCHANGED(barcode(Sku s)) AND name(currentUser()) != 'admin' MESSAGE 'Only the administrator is allowed to change the barcode for an already created product';
sku = DATA Sku (OrderDetail);
in = DATA BOOLEAN (Sku, Customer);
CONSTRAINT sku(OrderDetail d) AND NOT in(sku(d), customer(order(d)))
CHECKED BY sku[OrderDetail] // a filter by available sku when selecting an item for an order line will be applied
MESSAGE 'In the order, a product unavailable to the user is selected for the selected customer';