Scriptable assignment of execution plans
-
- UpdatedJan 30, 2025
- 3 minutes to read
- Yokohama
- Building applications
Each catalog item has an associated execution plan, used whenever an item of that type is ordered; if no plan is specified, the default plan is used. This default is effective for most organizations, but your execution plan may need to vary based on additional criteria.
For example, in the base system service catalog, a request for a new PC always uses the PC Delivery Plan. However, this plan may need to vary for unusual circumstances - such as when a requester is working from home, at a remote location.
To provide this flexibility, you can use a script to override the default execution plan on a specific catalog item.
Limitations during script execution
Execution plan scripts have limitations that need to be considered during their implementation.
While the execution plan script runs:
- You cannot interact with any catalog tasks as catalog tasks are only created after the execution plan is selected.
- Some fields such as total delivery time and due date are not yet calculated, although the request itself is available within the script via current.request().
- Approvals have not yet been generated.
Writing the scripts
Follow these guidelines when writing execution plan scripts.
Execution plan scripts can access the same global variables and other functions as in any other server side execution plan.
- current is the currently-requested catalog item,
sc_req_item
. - current.delivery_plan() is the assigned execution plan for this catalog item.
The evaluated value from the script is used as the sys_id
of the execution plan.
Simple example:
If an invalid value is returned, such as undefined or not found, then the existing assigned value is used.
More complex example:
In this example, any time a request is for a user in Atlanta, ServiceNow uses the Remote PC Delivery Plan. Otherwise, the execution plan is not overridden and ServiceNow uses the catalog item's normal execution plan, the PC Delivery Plan.
Add a script to a catalog item
You can add a script to a catalog item so that the script runs each time a user requests that item.
Procedure
Result
Use a script to approve an execution plan
You can use an approval rule script to approve an execution plan.
Procedure
- Retrieve an approval execution plan task.
- View the Approval Script field.
- Fill in an approval script using the same syntax and rules you would use on an approval rule.
Example
For example, in the script below, the requester’s manager is the approver.
