How to create a dynamic filter on a related list (EDIT BUTTON)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2016 11:32 AM
Hey Folks of ServiceNow! I was wondering if there is a way to create a default filter in related list that references a many to many tables and that it must be dynamic! the issue I am having is because of the fact the tables Im using there is many to many relationship so when I try to get(or choose) information on a related list I get all of the data that it contains without restrictions! I would like to set a default filter that takes the current reference item that it has in common so it would only show the items associated to it for each form (each device in this case for what I am doing).. heres an example!
for example this is what I get in this related list without using a filter:
All of the elements in that table! but from those elements I only need those that has the "product" of the current table that has this related list:
in this case I only want to see those that belongs to this Panasonic Product, that could be achieved by a static default filter(I was able to do that) but it doesnt work because not all of the actions has as product like this panasonic device so another way to do this is manually each time you go into this slushbucket you create a filter for it:
wich is not good! we dont want to be creating filters each time we enter into this slushbucket we would like to have an automated dynamic filter for it! I've tryied everything but now I wonder if this is even possible or achievable?? thank you very much!
What I have tried:
*** Go into List control of this related list and modify the layout to show "Edit default filter" builder condition field.
*** Going into the dictionary of this field and modifying the UI Policy that hinders "the reference qualifier fields" , tested with a dynamic filter and it doesnt allows you to selec the dynamic filter you just created it doesnt even appear in the list of dynamic filters when you need to choose nor any dynamic filter.
*** Creating a ref qualifier for it. (DIDNT WORK).
*** Then I modified the "dynamic filter" field and created a dyanamic scripted filter as well didnt work, it doesnt show the filter once it is created.
*** All kind of different stuff and IT DIDNT WORK!
Thank you very much Guys in regard Jose

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 06:57 AM
Unfortunately, there is no way to do this at this time. I've seen this request before. Perhaps you should submit an enhancement request on HI so the developers get some visibility.
Sorry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 10:22 AM
One easy way to do this would be to override the global "Edit..." button for your related list and have the new "Edit..." button attach an encoded query when opening the "Edit members" slushbucket. The encoded query will become the default filter.
1. Copy the global "Edit..." UI Action and make sure you have the same "Action name", i.e. "sysverb_edit_m2m" for a many-to-may "Edit..." button.
2. Make the new "Edit..." UI Action execute for your many-to-many table instead of Global
3. Edit the script to insert the line below together with the other "uri.set..." lines:
uri.set('sysparm_query', [your encoded query as a string]);
i.e.
uri.set('sysparm_query', 'product.name=' + parent.product.name); // Where parent.product.name refers to the product reference field in your main form.
I've got this to work on atleast Fuji, Geneva and Helsinki...
Good luck!
/Lars Bolk

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2016 10:26 AM
Impressive. I'll be eager to hear if Jose gets it to work. Thanks for sharing!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 11:20 AM
Lars, you rock. This is exactly what I needed for a "Client" related list that I have for Change Orders. We have a M2M relationship with clients (it's a user table) and change requests. All I had to add was:
uri.set('sysparm_query','u_active=true');
to the script for the "Edit..." button (and of course set the table on the button), and it works like a dream. Thank you!