client script to refresh a list in a tab

georgechen
Kilo Guru

Hello folks,

How can i refresh a list in a tab in a form with client script on the form?   For example, when a record is saved, the Task SLAs tab does not immediately get updated, and the users need to click the Task = Form for Processing link (see below) to refresh the list.  

find_real_file.png

Thanks in advance.

1 ACCEPTED SOLUTION

Hi George,



I tried and here is the final script you have to write.


Script :


function onLoad() {


    //Type appropriate comment here, and begin script below


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


}


View solution in original post

8 REPLIES 8

mikeblack
Tera Contributor

You can achieve this by below piece of code in your client script. You need to execute this based upon some logic



setTimeout(function(){ GlideList2.get("your_table_name").refresh(); }, 2000);


Thank you for this tip,   I have referred to Pradeep's wiki, and use the code below



function onLoad() {


      try {


              var elementLookup = $$('div.tabs2_list');


              var listName = "Task SLA";


              for (i = 0; i != elementLookup.length; i++) {


                      if (elementLookup[i].innerHTML.indexOf(listName) != -1) {


                              var listHTML = elementLookup[i].id.split('_');


                              var listID = listHTML[2];


                              nowRefresh(listID);


                      }


              }


      }


      catch (err) {


              alert(err.message);


      }


     


function nowRefresh(id) {


    GlideList2.get(id).refresh('');


}


}




I don't understand why it pops 'undefined' on       GlideList2.get(id).refresh('');,     the tab does not have a refresh button, does this make a difference?


find_real_file.png



Any advice would be appreciated.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi George,



The below blog should answer your question.


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


Thanks Pradeep, I refer to the form, and have the code as a new client script on form_load




function onLoad() {



     


      try {


              var elementLookup = $$('div.tabs2_list');


              var listName = "Task SLA";


              for (i = 0; i != elementLookup.length; i++) {


                      if (elementLookup[i].innerHTML.indexOf(listName) != -1) {


                              //alert ('element ' + elementLookup[i].innerHTML + ' found');


                              var listHTML = elementLookup[i].id.split('_');


                              alert ('listHTML=' + listHTML);


                              var listID = listHTML[2];


                              alert ('listID=' + listID);


                              //nowRefresh(listID);


                      }


              }


      }


      catch (err) {


              alert(err.message);


      }


             


      function nowRefresh(id) {                              


                      GlideList2.get(id).refresh('');                                                                      


      }



     


}



When form loads, it pops up with the warnings,





find_real_file.png



If you could help, it would be greatly appreciated.



Regards,