Server-side scripts

concept brazil Updated Sep 10, 2026 1 min read c_ServerScripting.md
Raw file servicenow.com

Server-side scripts run on the server or database. They can change the appearance or behavior of ServiceNow or run as business rules when records and tables are accessed or modified.

Server-side JavaScript APIs provide classes and methods that you can use in scripts to perform server-side tasks. Server-side scripts run in either the global scope or a scoped application scope, which determines which APIs are accessible.

Immediately invoked function expressions

The system uses immediately invoked function expressions when a script runs in a single context, such as in a Create a transform map. Functions that run from multiple contexts use Script includes instead.

By enclosing a script in an immediately invoked function expression, you can:

  • Ensure that the script does not impact other areas of the product, such as by overwriting global variables.
  • Pass useful variables or objects as parameters.
  • Identify function names in stack traces.
  • Eliminate having to make separate function calls.

An immediately invoked function expression follows this format:

JavaScript
(function functionName(parameter){   //The script you want to run })('value');//Note the parenthesis indicating this function should run.

You can declare functions within the immediately invoked function expression. These inner functions are accessible only from within the immediately invoked function expression.

JavaScript
(function functionName(parameter){   function helperFunction(parameter){//return some value}   var value = helperFunction(parameter);//Valid function call.   //perform any other script actions })('value'); var value2 = helperFunction(parameter);//Invalid. This function is not accessible from outside the self-executing function.

Parent Topic:Writing server-side scripts

Search documentation
Search document titles and file paths on the brazil branch