Refresh a related list on field change

oharel
Kilo Sage

Hi guys,

Is there any way to refresh a related list when a field changes on the form?

For example: if I change the category on an incident form, I would like the related list category-articles to update, without saving the form first.

I tried an onChange client script with the following:

GlideList2.get(g_form.getTableName() + '.REL:31336814db772200e4257cbdae9619f4').setFilterAndRefresh('');

But I am not sure it can work without saving the form, which sort of makes this irrelevant.

Ideas?

harel

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

The wiki says that g_list is used in UI Context Menus and UI Actions:



GlideList2 (g list) - ServiceNow Wiki


View solution in original post

22 REPLIES 22

Mike Allen
Mega Sage

The wiki says that g_list is used in UI Context Menus and UI Actions:



GlideList2 (g list) - ServiceNow Wiki


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Harel,



Can you check on this. This could be helpful for you.



Reload a Form or Related list from a Client Script - ServiceNow Guru



GlideList2 (g list) - ServiceNow Wiki



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Thanks Ankur,



Already checked those...


I'm afraid Mike is right (that is, I'm afraid I can't do what I want, not that Mike is right...)


Thanks guys.



harel


If you don't mind venturing into the DOM, adding this line to onChange will refresh the Related List:



document.querySelector('div.related[tab_caption="Task SLAs"] span.breadcrumb_container a:last-of-type').click();



where "Task SLAs" in this example is the label for the Related List. It clicks on the last filter condition of the breadcrumb to make sure you apply and retain the entire filter.



Using GlideList2 like below works as well, but I noticed it filters only on the default filter condition (because we're not passing the filter as an argument), losing the rest of the breadcrumb in case you have multiple filter conditions:



GlideList2.get(g_form.getTableName() + '.task_sla.task').setFilterAndRefresh();



If you want to mimic the construct of the GlideList2 line above, you can use



document.querySelector('div[tab_list_name_raw="' + g_form.getTableName() + '.task_sla.task"] span.breadcrumb_container a:last-of-type').click();



EDIT: replaced :last-child with :last-of-type, which makes it more specific



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award