How to apply a default filter on a Related list and "lock" it so users cannot change it

PaulaaO
Mega Sage

Hi Community,

 

I need to apply a default filter on a related list which I managed to do (used the Set as default filter option from

Solved: How to set Default Filter on related list for all ... - ServiceNow Community ), however I have the requirement to "lock" this filter so it cannot be removed by users, but allow them to keep on building the filter if they want to.

 

I've tried various combinations from List Layout control such as omit filter or restrict the filter by roles, but in most cases I only manage to make the filter icon unavailable.

 

Is this possible at all?

 

Thank you.

 

Paula

1 ACCEPTED SOLUTION

This will re-create the out of box filter:

current.addEncodedQuery('top_task=' + parent.sys_id);

so it looks like the full one would be:

current.addEncodedQuery('top_task=' + parent.sys_id + '^u_dependency_typeINinternal,external,3rd_party,other');

'parent' here refers to the pm_project table record.

 

View solution in original post

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Hi Paula,

Consider the approach of re-creating the Related List by creating a Relationship with the same Applies to and Queries from tables.  The script would link to the parent record, then add whatever is in your default filter.  You would then show this Related List on the form instead of the out of box one.

 

In the scenario of the Incident Tasks Related List on the incident form that only filters on incident = <<current record>> let's say I want to also only show active tasks.  The Relationship looks like this:

BradBowman_0-1736357174627.png

You can use the same Name as the existing Related List, or whatever you want to show on the tab.  When users manually alter the filter on this custom Related List, they won't see the existing criteria, but can add to it.

 

Hi @Brad Bowman  many thanks for the suggestion. I've tried to implement it but I'm stuck with applying the filter correctly, this is as far as I got

 

 

 

 

(function refineQuery(current, top_task) {

	// Add your code here, such as current.addQuery(field, value);
	current.addEncodedQuery('pm_project=' + top_task.sys_id + '^u_dependency_type="other"')

})(current, top_task);

 

 

 

 

I've tried a few combinations to replicate this query of how the filter is applied on the list of records:

top_task=a847846c1bfd5654b436a86fe54bcb72^u_dependency_typeINinternal,external,3rd_party,other

 

Any ideas how I can correct the above? So far the related list returns all Project Task records from the system. I only got as far as to filter the active ones as I tried your example first.

 

Thank you.

 

Paula

Which out of box Related List on which form are you re-creating?

Project Task related list which sits on the Project -> pm_project_task.top_task