IT CanvassTalk to an advisor
ServiceNow Examples · LessonReviewed by Neelima, ServiceNow Architect · Updated · Published · current release · reference

ServiceNow Business rule examples

Before, after and async business rule patterns.

Quick answer

A business rule is server-side script that runs before or after a record is inserted or updated. The three patterns cover most needs: a before insert rule that sets a field with current.setValue, a before update rule that calls gs.addErrorMessage and current.setAbortAction(true) to stop a save that fails a condition, and an after insert rule that creates related records.

Key takeaways
  • Set a field before insert
  • Abort a save with a message
  • Trigger side effects after insert

Business rules run on the server around database operations. These patterns cover the everyday cases.

Set a field before insert

// When: before, insert
current.setValue('u_source', 'portal');

Abort a save with a message

// When: before, update
if (current.priority == 1 && !current.assignment_group) {
  gs.addErrorMessage('P1 needs an assignment group');
  current.setAbortAction(true);
}

Trigger side effects after insert

// When: after, insert
var t = new GlideRecord('task_sla');
// ...create related records, notifications, etc.
Try it YourselfJavaScript
▸ Press Run to execute.

Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.

Practise this on your own free instance.
Set up your free instance →
Already working on ServiceNow and stuck on a live ticket?Get an expert ServiceNow developer on screen-share to finish your daily tasks with you. Deliver on time, protect your reputation and your job. Monthly support only, no task-wise plans.Task assigned · no idea where to startStill stuck · your job on the lineExpert joins your screenDelivered on timeExplore On Job Support