Update Filter & Refresh Embedded List Using onChange Client Script

MC_Soria
Kilo Expert

Good day all,

I have a requirement to be able to have an embedded list update it's filter and then refresh when the value of another field changes. I have not been able to make this work. This has been asked before and I've looked through the following links:

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

ServiceNow Community - How to refresh a related list via script/ui action

ServiceNow Community - Refresh a related list on field change

Based on the above, I have written the following client script:

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

try {
var ci = g_form.getValue('cmdb_ci');
var elementLookup = $$('div.tabs2_list');
var listName = "REL:88bb021bdb38e3c0b0ed5a35dc9619e7"; // DOC Staging Table
for (i = 0; i != elementLookup.length; i++) {
if (elementLookup[i].innerHTML.indexOf(listName) != -1) {
var listHTML = elementLookup[i].id.split('_');
var listID = listHTML[0];
nowRefresh(listID,ci);
}
}
}

catch(err){
alert("Error: " + err.message);
}

function nowRefresh(id,app) {
GlideList2.get(id).setFilterAndRefresh('u_application_ci_2=' + app);
}
// gsftSubmit(gel('sysverb_update_and_stay'));
}

When the value of the cmdb_ci field changes - nothing appears to happen on the form. We would like the embedded list ("DOC Staging Table) to refresh to show records matching a query using the value in the cmdb_ci field.

The last link appears to have a solution, but it requires DOM Manipulation. Not wanting to deviate from best practice, I'm hoping someone has found another way to do this. Can anyone see if maybe my script is wrong, or if they know of another way?

Thanks for any assistance offered.

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

No way to do this without DOM manipulation I'm afraid.

View solution in original post

3 REPLIES 3

Mark Stanger
Giga Sage

No way to do this without DOM manipulation I'm afraid.

Thanks very much for the confirmation Mark!

dasbiswa
Tera Expert

Hi Soria,

Did you find a way as i am unable to understand what shall i use in place of this code

:

var listName = "REL:88bb021bdb38e3c0b0ed5a35dc9619e7"; // DOC Staging Table

If you can share your comment , this will be very helpful