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

Helsinki.


The label was copy-pasted...


I tested it in Helsinki using the below Client Script with the "Task SLAs" Related List (please rename it to your RL label) and it worked fine, as demonstrated by the screenshots below (the screenshots don't prove the RL was refreshed, but it shows the selector successfully selected the last filter condition - when this runs on yours, you'll be able to confirm the RL indeed gets refreshed):



function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  if (isLoading || newValue === '') {
          return;
  }


  //Type appropriate comment here, and begin script below
  var filter = document.querySelector('div.related[tab_caption="Task SLAs"] span.breadcrumb_container a:last-of-type');
  alert(filter.outerHTML);
  filter.click();
}



If this still fails to run on yours, you can reduce the filter variable gradually to see where it fails, like



var filter = document.querySelector('div.related[tab_caption="Task SLAs"] span.breadcrumb_container');


var filter = document.querySelector('div.related[tab_caption="Task SLAs"] span.breadcrumb');


var filter = document.querySelector('div.related[tab_caption="Task SLAs"]');



Sorry, it's taking more efforts than I thought - hope it's all worth the extra effort. Also, if you let me know which UI you're using, it might help.



Windows 8.1 IE11


find_real_file.png



Windows 8.1 Chrome Version 55.0.2883.87 m (showing only the default filter condition, as intended)


find_real_file.png


Windows 8.1 FireFox 50.0 (showing only the default filter condition, as intended)


find_real_file.png


Hi John,



I am using Firefox and Chrome. The first two filter lines produced "onChange script error: TypeError: filter is null function ".


The last one produced a long output - I can share if you want, but I am not sure it is worth your time...


Thanks anyway for putting-in the effort!



harel


If you can share with me, I'll take a quick look.


If you can share the contents of the alert box (in Chrome, just press Ctrl-C; in FireFox, select the text and copy), that would be more helpful.