GlideAjax getXMLWait() not working

adilbelahbib
Kilo Expert

Hey,

I'm trying to run simple script on a UI action that gets the group of the connected user. I created the script include and I used it in many other places using Ajax Asynchronous calls. However, when I tried to call it using a synchronous call, I got a 'null' result, as if the script doesn't wait for the answer to come.

Here's is a snippet from my UI Action containing the ajax call.

  var ajax = new GlideAjax('GetAssignementGroup');

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

  ajax.getXMLWait();

  var group = ajax.getAnswer();

  alert(group); //Prints 'null'

As I said, I'm already using the same script include with asynchronous calls and it's working. Do you have any ideas ?

14 REPLIES 14

xiaix
Tera Guru

What is your Script Include returning?


The sys_id of a group


Your client script code is correct.   May I please see your Script Include code?


var GetAssignementGroup = Class.create();


GetAssignementGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {




      getGroup: function()


      {


              var _sysID = 'sysID not found';


              var gr = new GlideRecord('sys_user_group');


              gr.addQuery('name', 'Name of Group I am looking for');


              gr.query();


              if (gr.next())


                      _sysID = gr.sys_id.toString();


                     


              return _sysID;


      }


});







Simply change the 'Name of Group I am looking for' to the name of the group you're trying to get the sys_id for, and you'll be all set.