How to apply different list filters based on navigation context (reference vs. direct access)?

Rosfield
Tera Contributor

Hi all,

I'm trying to conditionally filter a list view of the cmdb_ci_server table depending on how the user navigates to it.

‌‌Goal:
If the list is accessed directly via table navigation (e.g., cmdb_ci_server_list.do)
→ I want to apply a filter: manufacturer = VMware, Inc.

If the list is accessed via a reference field (e.g., u_server)
→ I want to show all records without any filter.

 

‌‌Question:
Is there any reliable way to distinguish whether a list view is opened from a reference field
or accessed directly via the table list view (e.g., cmdb_ci_server_list.do),
so I can conditionally apply the filter?

Alternatively, is there another recommended approach to apply different filters
based on how the list view was accessed?

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

@Rosfield 

you can do this

If the list is accessed directly via table navigation (e.g., cmdb_ci_server_list.do)
→ I want to apply a filter: manufacturer = VMware, Inc.

-> use Query business rule on that table and check the URL contains table_list and is not called via reference qualifier, if yes then apply filter for manufacturer

If the list is accessed via a reference field (e.g., u_server)
→ I want to show all records without any filter. -> apply reference qualifier and show all

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

@Rosfield 

you can do this

If the list is accessed directly via table navigation (e.g., cmdb_ci_server_list.do)
→ I want to apply a filter: manufacturer = VMware, Inc.

-> use Query business rule on that table and check the URL contains table_list and is not called via reference qualifier, if yes then apply filter for manufacturer

If the list is accessed via a reference field (e.g., u_server)
→ I want to show all records without any filter. -> apply reference qualifier and show all

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you! I got a useful hint from your idea.
I applied the business query as shown below, and I confirmed that it's working as expected.
Just wanted to check — is it okay to keep using this approach moving forward?
Thanks again!

var url = gs.action.getGlideURI().toString();

var isReference = url.indexOf('sysparm_reference') !== -1;
var isListView = url.indexOf('_list.do') !== -1;

if (isListView && !isReference) {
current.addEncodedQuery('manufacturer.name=VMware, Inc.');
}