Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Enabling Script Includes in Condition Builder and Reports with Sandbox Support

rohanaditya
Kilo Sage

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.

Screenshot 2025-08-05 at 5.59.51 PM.png

 

Steps to Create the Script Include

  1. Navigate to System Definition > Script Includes

  2. Click New

  3. Fill out the form as follows:

    • Name: ReportsAJAX

    • Accessible from: All Application Scopes

    • Sandbox: Checked

  4. 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();

 

condition-builder.png

And we get

Screenshot 2025-08-05 at 5.45.08 PM.png

 

Hope this helps!

Explore more ServiceNow tips and tutorials on my blog: Rohan's ServiceNow blog

0 REPLIES 0