O'Reilly logo

Mastering ServiceNow by Martin Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Preventing colliding code

In ServiceNow, almost all JavaScript you write will be in the global scope by default. The scope of a variable refers to where it can be accessed, meaning that, by default, code in one Business Rule can affect another.

Consider the example of a Business Rule that runs at order 100. Any variables defined in this Business Rule will be available to one that runs at order 200. In fact, the platform relies upon this behavior: current, previous, gs, and the likes are defined as global variables, and are available everywhere. You may like to think that ServiceNow just concatenates all the code in the Business Rules together, and makes one huge script that runs when a record is updated.

If you search the Web, you will find many ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required