Reference qualifiers
Summarize
Summary of Reference qualifiers
Reference qualifiers in ServiceNow allow you to filter the data returned for a reference field, which links to a field on another table. By default, reference fields display all values from the referenced table, but reference qualifiers enable you to restrict this to a specific subset, such as only active users or users with certain roles. This filtering improves usability and relevance of reference lookups on forms.
Show less
Reference qualifiers can be defined at the table or extended table level using the Dictionary Entry form or dictionary overrides. They are not applicable to condition builders, which use dynamic filter options instead. Implementing reference qualifiers requires understanding the ServiceNow data model and scripting capabilities. For data access restrictions by user, use ACLs rather than reference qualifiers.
Types of Reference Qualifiers
- Simple Reference Qualifiers: Use basic AND/OR conditions (up to 13) to filter records. Suitable for straightforward filters such as active companies or users with a specific role.
- Dynamic Reference Qualifiers: Utilize stored dynamic filter options that include encoded queries or script includes. These filters can be reused across multiple forms and are ideal for enabling non-developers to apply consistent filtering. The base system includes several out-of-the-box (OOB) dynamic filters.
- Advanced Reference Qualifiers: Allow inline encoded query strings or JavaScript code within the Reference qual field, typically for unique filters not shared across multiple fields. JavaScript calls are recommended to script includes rather than global business rules for maintainability.
Key Features and Usage
- Reference qualifiers filter the available options on reference fields dynamically when a form loads.
- JavaScript
currentobject can be used in qualifiers to filter based on values of the active record, enabling context-sensitive filtering (e.g., filtering users by the company of the current record). - Use dot-walking syntax to access related fields, such as
current.assignedto.emailto filter by user email. - When a field appears on multiple related lists, a unique
listEditRefQualTagcan be set in the list control to enable tailored filtering scripts for each related list context. - The
INSTANCEOFoperator helps simplify complex class-based qualifiers.
Practical Benefits for ServiceNow Customers
- Improves user experience by showing only relevant reference data, reducing clutter and errors.
- Supports complex filtering scenarios with a balance of ease-of-use via simple qualifiers and flexibility via advanced scripting.
- Enables reuse and centralized management of filters through dynamic filter options.
- Allows developers and administrators to tailor reference data visibility precisely according to business needs.
Use reference qualifiers to filter the data that is returned for a reference field.
A reference field stores a link (reference) to a field on another table, making the records/fields in the referenced table available to the form containing the reference field.
For example, the Assigned to field on the Incident table is a reference to the User [sys_user] table. By default, all values for the field that is being referenced appear in the reference lookup and can be directly accessed through the reference field (type ahead). Expanding on the prior example, if a reference qualifier is not defined, all users in the User table appear in the reference lookup. Including those users that are inactive. Sometimes, this might be the desired functionality. In other cases however, only a subset of the available values may be desired. In this case, create a reference qualifier to filter the available data so that only the desired values are returned and made available to the form. Such as only the active users or users that have a specific role. Reference qualifiers are robust and can consist of simple AND/OR conditions, inline JavaScript, or complex script include.
- Creating reference qualifiers requires knowledge of the underlying ServiceNow data model (tables and fields) and knowledge of the Web services and Scripts.
- To restrict what data specific users can access, use ACLs not reference qualifiers.
You can define a reference qualifier using one of the following methods.
Simple reference qualifier
Simple reference qualifiers use AND/OR statements (conditions) to create simple filters. Use simple reference qualifiers when filtering on conditions such as whether a company is active, a user has a specific role, and/or a caller is in a specific time zone. Simple reference qualifiers can have a maximum of 13 reference qualifier conditions. For additional information on how to use condition builders, see Condition builder.
Dynamic reference qualifiers
Dynamic reference qualifiers enable you to use a Create a dynamic filter option to run a query against a reference field to filter the returned data set. Dynamic filter options are stored filters that can contain Encoded query strings, JavaScript, or script includes, and can be used in multiple dynamic reference qualifiers. Changes made to a dynamic filter option automatically apply to all reference qualifiers that use the same dynamic filter option. Use this type of reference qualifier when you want to use the same filter on multiple forms or to provide filter functionality to "non-code savvy" implementers.
The base instance provides several OOB dynamic filter options. If a dynamic filter option that meets your needs does not exist, you can create a new dynamic filter option that is specific to your requirements. An example of an OOB dynamic filter option is the reference qualifier on the Model ID field on a configuration item form, such as the Computer form. The reference qualifier calls the CI Model Qualifier dynamic filter option, which in turn calls the ModelAndCategoryFilters script include. This script include filters the data set based on the class of the CI. The only options for the model ID are options that belong to the same class as the current CI. For example, only CIs that belong to the Computer class are available in the Model ID field on the Computer form.
Advanced reference qualifier
vendor=true, which returns all companies that are designated as
vendors. Entering this string is the same as using the condition builder as shown in the
example for the simple reference qualifier. For additional information on valid encoded
query string syntax and examples, see Encoded query strings.javascript:new
myScriptInclude().my_refqual(). This code calls the function
my_refqual() in the script include
myScriptInclude(). The function must return a query string that can
filter the options available on a reference field.javascript:'u_active=true^' +
"u_hr_service="+current.hr_service in reference qualifiers.return "company=" + current.company;javascript:"company=" + current.companyFor an additional example, configuring the reference field to show only users of a specific group, see the How to select only users of a specific group into a reference field [KB0831564] article in the Now Support Knowledge Base
.Related lists and reference qualifiers
// Advanced reference qualifier on the CI Relationship Child field that takes into account
// the related list that we are editing the child field on, if the field is being edited
// from a tagged related list.
cmdb_rel_ci_child_refQual:function(){
if(listEditRefQualTag =="application") return "sys_class_name = cmdb_ci_appl";
if(listEditRefQualTag =="database") return "sys_class_name = cmdb_ci_database"
}Using Javascript current syntax in reference qualifiers
current is a JavaScript object that contains the fields and field values
of the active (current) record. For forms, this is the record that is displayed (loaded) in
the form. Within advanced and dynamic reference qualifiers, you can use the JavaScript
current object to define filters such as javascript:"company=" +
current.company.
This JavaScript, within a reference qualifier, only returns the records from the referenced table that are equal to the company field value of the current record. So, if the value that appears in the Company field is Acme, the JavaScript returns all reference field records whose company value is equal to Acme (company="Acme"). If you then bring up a record whose company value is "ViewRite", the JavaScript resolves to company="ViewRite."
All fields within the currently loaded form (tables) are available for use with the
current object. Use dot-walking to access values in a table, including the referenced table. For
example, on the Incident form, the Assigned To field references the
User table. To access the email address of the user, use the following syntax:
javascript:"emailAddress=" + current.assigned_to.email.