Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Refreshing list after AJAX call

filip11
Giga Contributor

Hello.

I have built a client list UI Action designed as List Choice. This action takes the checked rows and sends them via GlideAJAX to server. Server processes them and sends back a result. I want to refresh the list after the reply (result) arrives back to client, but am unable to do so. The script I am trying to use is:

function send() {

        var checked = g_list.getChecked();

        var sendGA = new GlideAjax('script_include_name');

        sendGA.addParam('sysparm_name', 'method_name');

        sendGA.addParam('sysparm_ids', checked);

        sendGA.getXML(parseResponse);

}

function parseResponse(response) {

        g_list.refresh();

}

The problem is, the list does not refresh. It does if I put the refresh() method call to the 'send' function, but I want to refresh the list only after I get the response from server, so that the changes will be visible on refresh.

I am using Fuji Patch 4 and developing a scoped application.

Thank you very much.

1 ACCEPTED SOLUTION

Mike Allen
Mega Sage

I did this:



GlideList2.get(g_form.getTableName() + '.incident.parent').setFilterAndRefresh('');



function continueOK(){


  //Get the selected values from the right slushbucket


  var values = slush.getValues(slush.getRightSelect());


  //Get the sys_id of the current record


  var taskID = g_form.getUniqueValue();


  if(values == ''){


  alert("At least one must be selected");


  return;


  }


  //Update the incident records


  var ajax = new GlideAjax('Ajax');


  ajax.addParam('sysparm_name', 'ajaxFunction');


  ajax.addParam('sysparm_taskID', taskID);


  ajax.addParam('sysparm_values', values);


  ajax.getXML(addAjaxResponse);



  GlideList2.get(g_form.getTableName() + '.incident.parent').setFilterAndRefresh('');


}


View solution in original post

2 REPLIES 2

Mike Allen
Mega Sage

I did this:



GlideList2.get(g_form.getTableName() + '.incident.parent').setFilterAndRefresh('');



function continueOK(){


  //Get the selected values from the right slushbucket


  var values = slush.getValues(slush.getRightSelect());


  //Get the sys_id of the current record


  var taskID = g_form.getUniqueValue();


  if(values == ''){


  alert("At least one must be selected");


  return;


  }


  //Update the incident records


  var ajax = new GlideAjax('Ajax');


  ajax.addParam('sysparm_name', 'ajaxFunction');


  ajax.addParam('sysparm_taskID', taskID);


  ajax.addParam('sysparm_values', values);


  ajax.getXML(addAjaxResponse);



  GlideList2.get(g_form.getTableName() + '.incident.parent').setFilterAndRefresh('');


}


Thank you very much Mike, this works great! I just had to hardcode the table name, as g_form seems unavailable on lists, but that is not a problem.