Script examples

Now that we have seen how the basics of server-side scripting work, we can take a look at some scripting examples to further our knowledge of how to use these introductory server-side techniques.

We'll start with a further business rule example.

This time, we will create a before delete business rule to ensure that directors are not deleted. We need to set the business rule to advanced; select the delete checkbox and before in the When field. Let's have a look at the code:

(function executeRule(current, previous /*null when async*/) {  if (current.title == 'Director') {    gs.addErrorMessage('Cannot delete Director');    current.setAbortAction(true);    action.setRedirectURL(current);  }})(current, previous);

Here, we are checking whether ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.