Is there ability to set up a filter that is editable on a reference field?

Su522
Kilo Sage

It is my understanding that the ability to set up a filter that is editable on a reference field is not currently available.
Is this correct?

 

Specifically, we're looking for a way to filter a "Contact" reference field on a table by the same "Account" on the record.
So only the Contact for that Account initially show up when clicking on the "Lookup using list" button (see screenshot)
But then, clicking the "All" breadcrumb would remove that filter and show all Contacts

 

Is there a workaround?
Such as a customization that we could do to allow this?

 

Help is greatly appreciated!

Thank you.

10 REPLIES 10

@Su522 Please mark the response an accepted solution if it addressed your question.

@Sandeep Rajput That post was from 7 years ago. I understand creating an editable default filter in the reference lookup list is not supported by the platform, but I am asking if there is a way to do this with a customization. 

@Su522 The main reason why such a feature doesn't exist is because it defeats the purpose of the reference qualifier on the reference field. If the users are allowed to change filter set by reference qualifier then anyone can select any random value using the All filter even if the value is incorrect for the reference field.

 

e.g. Users from Germany should only be able to see Assignment group from Germany to assign a ticket. Now this can be easily achieved via a reference qualifier, however if the users have an option to select any random group from any other country using All filter and save the ticket, the ticket will be assigned to incorrect group. 

 

I wouldn't suggest to achieve your requirement via any customisation as it will create more headaches for you in the future.

@Su522 This is exactly correct. This is why I suggested using it as a training or process review opportunity.

 

If you truly want to do the customization (although again I'd highly advise against too much customization), the following could work.

 

1. Create a true/false field on the table called something like "Override Account" or something else logical (again, I'd advise creating unnecessary fields)

2. Add the field to your form in a logical position

3. Add a scripted reference qualifier by selecting Advanced and entering the following:

 

if(current.account_ref_qual_override){'account='+current.account};

 

Where 'account_ref_qual_override' is the technical name of your custom field.

 

Ideally you put this into a script include and call the include from the Reference qual field. 

 

Again, I wouldn't advise this solution, but if it is a true business need then the above should work.

Community Alums
Not applicable

Hi @Su522 ,

This functionality is not directly possible in ServiceNow, as reference fields do not natively support an editable filter that can dynamically switch between predefined filters and allow users to remove the filter (e.g., by clicking the "All" breadcrumb). However, you can achieve similar functionality using the following approaches:

es, you can achieve this by creating additional fields on the form and dynamically updating the reference qualifier based on their values. This method allows you to refine the filter for a reference field based on multiple criteria defined by these fields. Here's how you can implement this:


Steps to Dynamically Update Reference Qualifier Based on Multiple Fields:

  1. Add Fields to the Form
    Add the necessary fields to the form that will serve as criteria for filtering. For example:

    • Account (e.g., account)
    • Region (e.g., region)
    • Department (e.g., department)
  2. Write a Dynamic Reference Qualifier
    Use a dynamic reference qualifier script on the reference field (e.g., Contact) to filter the data based on the values of the additional fields.

    Example Reference Qualifier Script:

    javascript
    Copy code
    var account = current.account; // Reference to Account var region = current.region; // Reference to Region var department = current.department; // Reference to Department var query = ''; if (account) { query += 'account=' + account; } if (region) { query += (query ? '^' : '') + 'region=' + region; } if (department) { query += (query ? '^' : '') + 'department=' + department; } return query;
  3. Use Client Script for Real-Time Updates
    Add an onChange Client Script for each of the filtering fields (e.g., Account, Region, Department) to refresh the reference field whenever a value changes.

    Example Client Script:

    javascript
    Copy code
    function onChange(control, oldValue, newValue, isLoading) { if (isLoading || oldValue === newValue) { return; } g_form.setValue('contact', ''); // Clear the contact field g_form.clearOptions('contact'); // Refresh the options }
  4. Test the Setup

    • Select or modify the filtering fields (e.g., Account, Region, Department).
    • Open the "Lookup using list" for the reference field (e.g., Contact) and verify that the results reflect the specified criteria.

Example Use Case:

If you have a form where users need to select a contact filtered by:

  • Account (the associated account)
  • Region (geographical region)
  • Department (specific department within the organization),

You can add these fields, use the reference qualifier script to dynamically build the query, and ensure the Contact reference field shows the appropriate filtered list.