Business rules run on the server when a record is displayed, inserted, updated, deleted or queried. current is the record being saved; previous is how it looked before the update.
Before: change current, it is saved anyway. After: update other records. Async: slow work in the background. Display: send data to the form with g_scratchpad.
(functionexecuteRule(current, previous) {
// Before rule: no update() needed, the change is saved with the recordif (current.getValue('priority') == '1') {
current.setValue('u_major_incident', true);
}
})(current, previous);
Cancels the insert, update or delete. Use it in a before rule, with a message.
(functionexecuteRule(current, previous) {
if (gs.nil(current.getValue('close_notes'))) {
gs.addErrorMessage('Add close notes before resolving.');
current.setAbortAction(true);
}
})(current, previous);
In after and async rules the record is already saved, so aborting does nothing.
In before rules the change is saved anyway; in after rules this re-runs every rule and can loop. Remove it.
Frequently asked questions
Should I use a before or an after business rule?
Use before to change or validate the record being saved; the change is stored with it, no update() needed. Use after to change other records or fire events once the save succeeded, and async for slow work such as integrations.