Allow users to modify the filter in the reference field search window

Sandhya23
Tera Guru

Scenario:

There is a custom table named "ABC", which contains:

  • A Location field (referencing the cmn_location table).
  • A Company field (referencing the core_company table).

Another table, "XYZ", also contains these two fields (Location and Company), and "XYZ" is referenced in the "ABC" table as a second reference field.

Requirement:

  1. When users click the search icon on the Location field in the ABC table:

    • The list of available locations should automatically filter based on the Company entered in the ABC form or, if a value exists, the Company of the second reference field (from the XYZ table).
  2. The filtered list of locations should be displayed as breadcrumbs in the search window, allowing users to modify the filter as needed. This enables them to view the complete list of locations and select any location, regardless of the values in the Company or second reference field.

Current Setup:

  • The system is domain-separated.
  • The existing reference qualifier for the Location field is:
    javascript
    CopyEdit
    javascript: 'sys_domain=' + current.sys_domain.toString();

What are the best approaches to meet this requirement while maintaining domain separation and ensuring users can modify the filter?

 

Regards,

 

1 REPLY 1

FeriHeri
Kilo Contributor

Hello, @Sandhya23 

 

Using Dynamic Reference Qualifier
Instead of writing custom JavaScript code, you can use Dynamic Reference Qualifiers for the Location field in the ABC table. ServiceNow allows you to create dynamic filters for reference fields based on conditions and values from other fields in the form.

Reference Qualifier for Location: Set the Reference Qualifier for the Location field to be dependent on the Company field and the XYZ table.
You can use a Condition reference qualifier where the filter is based on the Company field of the ABC table.
If the XYZ table has a value for the Company, it can also be referenced for filtering the Location list.
2. Breadcrumb Filtering
The ServiceNow platform supports a searchable reference field with a breadcrumb feature that allows users to adjust filters in the search window.

When the user clicks the search icon on the Location field, it will show the filtered list of locations based on the Company value from ABC or the XYZ table.
The filter condition (like filtering locations by Company) will be visible as a breadcrumb in the search window.
Users will have the option to remove or modify the filter criteria (breadcrumb) to view the complete list of locations, regardless of the company context, and then select a location.
3. Domain Separation
Ensure the Domain separation is maintained by:

Setting the reference qualifier to filter locations by the current domain (sys_domain).
Since the system is domain-separated, only the locations belonging to the same domain as the user's session will be available unless modified by the user via breadcrumbs.
4. Steps to Set It Up in UI:
Configure the Location Field: On the ABC table, set the Reference Qualifier for the Location field to be dynamic and dependent on the Company field.

Use a filter condition that filters the available locations based on the Company in ABC or Company from the XYZ table.
Enable Searchable Reference Field: Ensure the Location field is a searchable reference field so that the user can see the search window when they click the search icon.

Breadcrumbs Display: The filter applied based on Company will be shown as a breadcrumb in the search window. The user can interact with the breadcrumb to modify or remove the filter and see all available locations.

Domain Filtering: The system will still respect domain separation, and only locations within the same domain will be available by default, unless adjusted via the breadcrumb filter.

Summary:
Use dynamic reference qualifiers to filter locations based on the Company field in ABC or XYZ.
Enable searchable reference fields and allow the breadcrumbs feature to let users modify the filter.
Ensure domain separation by including domain-specific filters in the reference qualifier configuration.

 

Best Regards
feri865