Enabling Script Includes in Condition Builder and Reports with Sandbox Support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 05:16 AM - edited 08-05-2025 08:54 AM
Sometimes, when using a Script Include in the Condition Builder, you may get no results, even though your script is valid and tested.
No incident sys ids are returned
This usually happens because:
The Sandbox enabled option is not enabled on the Script Include.
The Script Include isn’t accessible from all scopes (if you're running it in a scoped app).
Ensuring these settings are configured correctly is essential for the script to work within filters and reports.
Steps to Create the Script Include
Navigate to System Definition > Script Includes
Click New
Fill out the form as follows:
Name: ReportsAJAX
Accessible from: All Application Scopes
Sandbox: Checked
Paste the following script into the Script field:
function ReportsAJAX() {
var incGr = new GlideRecord('incident');
incGr.addActiveQuery();
incGr.addQuery('priority', '1');
incGr.query();
var incidentArray = [];
while (incGr.next()) {
incidentArray.push(incGr.sys_id.toString());
}
return incidentArray;
}
⚠️ Important: If Sandbox is not checked, this script will fail when used in a filter, and you’ll waste hours debugging something that’s not broken. Don’t skip it!
When filtering records (e.g., in the Condition Builder for a list or report), use:
SYS ID → is one of → javascript:ReportsAJAX();
And we get
Hope this helps!
Explore more ServiceNow tips and tutorials on my blog: Rohan's ServiceNow blog
- Labels:
-
Incident Management
- 343 Views