OBLYTECH Logo
OBLYTECH Logo

ServiceNow Dynamic Filter Options: Setup for Reference Fields

A dynamic filter option is a stored filter record that runs an encoded query, JavaScript or a script include against a reference field. You create it under System Definition, Dynamic Filter Options, mark it Available for ref qual, and then pick it as the dynamic reference qualifier on a field, so one definition can serve many forms.

What a dynamic filter option is

A reference field points at a record on another table. The Assigned to field on an incident, for example, points at the User table. Left alone, the lookup behind that field shows the records of the referenced table, inactive users included. A reference qualifier narrows that list.

ServiceNow offers three kinds of reference qualifier: simple, dynamic and advanced. A dynamic filter option is the stored filter behind the dynamic kind. The stored filter can contain an encoded query string, JavaScript, or a script include. Think of it as the script given a name and a home in the platform, so that it can be selected rather than retyped.

Turning a script include or a piece of JavaScript into a named object has one practical effect, reuse. One option can sit behind several dynamic reference qualifiers, and when you edit the option, the qualifiers that use it change with it. A rule such as “models that fit this class” is then maintained in one place, not on each form.

The same records serve a second purpose. Condition builders use dynamic filter options through the is (dynamic) operator, which calls the option. The pre-existing Me option is the standard illustration: the pre-existing Me option is a dynamic filter option used in a condition.

When a dynamic option is the right type of qualifier

The three types suit different jobs.

Type How it is defined Fits when
Simple AND/OR conditions in a condition builder, up to 13 conditions The rule is a plain one, such as whether a company is active or a user holds a role
Dynamic A stored dynamic filter option The same filter is needed on several forms
Advanced An encoded query or JavaScript typed into the Reference qual field The filter is simple and unique and is not reused across reference fields

The deciding question is reuse. If a filter will be needed on more than one field, a dynamic option saves you from copying a script into several Reference qual fields and then fixing it in several places. If the filter belongs to one field, an advanced qualifier is enough, and calling a function in a script include is preferred over calling a global business rule.

Whichever type you choose, one reference qualifier can be defined per field, per form or table. To change the qualifier on an extended table and its children without touching the parent, use a dictionary override.

Qualifiers also have a boundary worth stating. They shape what a lookup offers; they do not secure data. To restrict what specific users can access, use access controls (ACLs) instead.

Find the dynamic filter options already in the instance

The base instance ships with a number of out-of-the-box dynamic filter options, so check before writing a new one. To see the ones that can serve as reference qualifiers:

  1. Go to System Definition, then Dynamic Filter Options.
  2. Select the filter icon at the upper right of the list.
  3. Add the condition Available for ref qual is true.

The list that remains holds the options selectable as dynamic reference qualifiers.

A built-in example shows the pattern. On the Computer form, the Model ID field uses the CI Model Qualifier option. That option calls the ModelAndCategoryFilters script include, which limits the models offered to the class of the configuration item. On the Computer form, only entries of the Computer class are available in Model ID. The form shows a named option rather than the script behind it.

Create a custom dynamic filter option

Creating an option requires the admin role. The steps run as follows.

  1. Create a scripted filter as a client-callable script include or as a business rule.
  2. Go to System Definition, then Dynamic Filter Options.
  3. Select New.
  4. Complete the form.
  5. Select Submit.

The form fields

Field What goes in it
Label A descriptive name for the option
Script The name of the function you created, JavaScript (no script include is needed), or a full script include or business rule call, for example new GlobalCanvasUtil().refQualPaTabs()
Field type Reference
Referenced table The table the option applies to
Order A number that sets where the option sits in the filter option choice list
Roles The role a user needs in order to see the option
Active Turns the option on or off
Reference script Optional. The client-callable script include or business rule for the scripted filter. It can stay empty when the Script field holds JavaScript, an encoded query, or a full script include or business rule reference
Available for filter Shows the option as a filter breadcrumb
Available for default Lets the option serve as a default in a dictionary entry
Available for ref qual Lets the option be selected as a dynamic reference qualifier

The last three are switches that decide where the option appears. An option meant for reference fields needs Available for ref qual. An option that should appear as a filter breadcrumb needs Available for filter. Roles names the role a user needs in order to see the option, and Active turns it on or off.

The Script field accepts three shapes of content, and the choice affects what else you fill in. A short encoded query or a snippet of JavaScript can go straight into Script, leaving Reference script empty. A call into a script include goes into Script as a full call, using the script include built in step one.

Three ways to define a dynamic filter

An administrator has three routes when a dynamic filter is needed. The first is an existing is (dynamic) option, which works in the condition builder only. The second is an existing dynamic filter option, either one that ships with the instance or one a colleague built earlier. The third is a new dynamic filter option, with its own script include or JavaScript behind it.

In practice the order of preference follows effort. Look for an option that already exists, and create a new one only when none fits. Because a new option adds a record that others will find in the choice list, a clear Label and a sensible Order value matter more than they might seem when you are the only one using it.

What the advanced alternative looks like

Seeing the advanced type makes the case for the dynamic one clearer. An advanced qualifier takes either an encoded query string or JavaScript directly in the Reference qual field. A string such as vendor=true returns only companies marked as vendors. A JavaScript call can point to a function in a script include, which is preferred over a global business rule.

The record on screen can feed the result. An expression such as javascript:"company=" + current.company returns only the records whose company matches the company on the loaded form. That works well for a single field. It becomes a maintenance cost the moment the same expression is pasted into a second and third field, which is the situation a dynamic filter option is meant to remove.

Things to know before you rely on one

Dynamic filters are supported in scoped applications. They are not supported in UI policy conditions, which rules out an is (dynamic) condition there.

A script inside a dynamic filter that uses Table API GET methods works for the user set up in the basic authentication profile. When several users need the option to work, write the script with the global JavaScript APIs GlideRecord and GlideQuery.

Reference qualifier scripts can read the record on screen through the current object, which holds the fields and values of the loaded record. Dot-walking reaches related records, as in an assigned user’s email address on the Incident form. When one field appears on several related lists on a form, the listEditRefQualTag variable lets a script tell the lists apart, using the tag entered in the List edit tag field of the list control.

Frequently asked questions

Where do I find dynamic filter options in ServiceNow?

Go to System Definition, then Dynamic Filter Options. Filtering that list on Available for ref qual is true shows the options that reference qualifiers can use.

Which role do I need to create one?

The admin role.

How is a dynamic reference qualifier different from an advanced one?

A dynamic qualifier runs a stored dynamic filter option that several fields can share. An advanced qualifier is an encoded query or JavaScript typed into the Reference qual field of one field, which suits a unique filter that is not reused.

What happens to my forms when I edit a dynamic filter option?

The reference qualifiers that use the option change with it, because they all run the same stored filter.

Can I use a dynamic filter option in a UI policy condition?

No. Dynamic filters are not supported in UI policy conditions.

How does a condition builder use a dynamic filter option?

Through the is (dynamic) operator, which calls the option; the pre-existing Me option is the standard example.