Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to Create Your Own Dynamic Filter Option in ServiceNow

Tejas Adhalrao
Kilo Sage

4078_TA_0-1768625007041.png

Dynamic Filter Options allow you to use JavaScript logic in filters instead of hard-coded values. This is very useful when filter results should change based on the logged-in user or business logic.

 

step 1)Create a Script Include that returns an array /string

4078_TA_1-1768625025007.png

Important: Enable Sandbox Enabled

 This is mandatory.

I personally wasted a full day because the filter was not working.
After enabling Sandbox Enabled, it started working correctly.

Why Sandbox Enabled is Required?

When ServiceNow runs JavaScript from Dynamic Filters, it is not normal server-side code.

  • The script is triggered from the UI / client side

  • For security reasons, ServiceNow runs it inside a sandbox

  • The sandbox allows read-only access and blocks unsafe operations

That’s why:

  • Your Script Include must be Sandbox Enabled

  • Otherwise, the dynamic filter will not execute

 

Step 2: Create Dynamic Filter Option

 

System Definition → Dynamic Filter Options -> new

4078_TA_3-1768625184438.png

 

 Label =This is the display name shown in the filter dropdown.

Script = call you script include

Field type =Type of value returned by script.

Referenced table : filter will apply on this table fields

 

 

 

 

thanks

tejas

1 REPLY 1

Lisa Conn
Tera Expert

Thank you for posting this, it was super helpful to me
1) i didn't know about enabling sandbox
2) i was converting the array to string. once I changed the script to not convert, it started working