0

I am unable to get the updated value from the function. The code is similar to Javascript and ajax.

var created_ByRegion = g_form.getValue('u_region');
var g_number = g_form.getValue("u_number");
var response = '';
var ga = new GlideAjax('getRegionUsers');
ga.addParam('sysparm_name', "getUsers");
ga.addParam('sysparm_region', created_ByRegion); //Onchange field is reference field to sys_user table

ga.getXMLAnswer(function(answer) {
  var response = answer;
});
alert(response);
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
jvk
  • 2,133
  • 3
  • 19
  • 28
  • The callback function you provide to `getXMLAnswer()` is asynchronous, therefore `alert(response)` has executed long before `var response = answer` has been invoked. To fix this, ***all*** logic dependant on the `answer` argument must be within, or invoked from, the callback you pass to `getXMLAnswer()`. See the duplicate for more details. – Rory McCrossan May 25 '23 at 14:08
  • Also `var` is functional scoped, so even without it been `async` you wound't be able to access `response` – Keith May 25 '23 at 14:11

0 Answers0