simple glideAjax in scoped app killing me

emyrold
Giga Expert

I'm building a small little custom app and the requirement needs me to auto set certain groups based on state.

typically I would do this with assignment rules but I have to also do other things that cannot be done with rules.

That said, I am leveraging UI Policy (if true or if false script blocks).

I have created a glide ajax Script Include in the new custom application scope with client callable checked.

I have created three system properties + system properties category and Module to display the properties in the application.

I have created a UI Policy with condition (state = draft) and then in the execute if true script block I have written a fairly simple glideAjax script.

The issue seems to be with parsing the result.   If I gs.warn() on the script include it correctly logs what I want just before calling "return" to send the results back to the client.

Here is the UI Policy Script:

function onCondition() {

  try {

  g_form.clearValue('assigned_to');

  g_form.setDisplay('assigned_to', false);

  var ga = new GlideAjax('u_docit_ajax');

  ga.addParam('sysparm_name', 'getGSDProperties');

  ga.addParam('sysparm_property', 'x_10032_gtd_dev.sn.developers.group');

  ga.getXML(myCallBack);

  }

  catch(err) {

  console.log(err);

  }

}

function myCallBack(response) {

  var answer = response.responesXML.documentElement.getAttribute("answer");

  alert('my answer is: ' + answer);

  //*** g_form.setValue('fieldname', 'sys_id', 'name') ***//

  //g_form.setValue('assigned_to', answer); //answer is coming back as: 'c0c602364f55d20036988ab18110c7f8', 'SN Developers'

}

Here is my Script Include:

var u_docit_ajax = Class.create();

u_docit_ajax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

//u_docit_ajax.prototype = Object.extendsObject(x_10032_gtd_dev.u_docit_ajax.AbstractAjaxProcessor, {

// u_docit_ajax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  /*

  * @getGSDProperties - GlideAjax function called from client script

  * @sysparm_property - This will be the sys_parameter name passed in from the client

  * @returns - The value of the given property

  */

  getGSDProperties: function() {

  var sysProp         = this.getParameter('sysparm_property');

  gs.warn('***DEBUG: gs.getProperty(sysProp) is: ' + gs.getProperty(sysProp));

  return gs.getProperty(sysProp);

  }

});

Here is an error in the system log when the Script Include is processing:

GlideAjaxError_01.png

And here is a Java console error when the client-side codes runs when form loads:

GlideAjaxError_02.PNG

1 ACCEPTED SOLUTION

HI Emyrold,



You need to have 2 properties or You need to split the property into display name and sys_id and   pass them separately for the   setValue method.



Hope this helps



Thanks


Srini


View solution in original post

26 REPLIES 26

manikorada
ServiceNow Employee
ServiceNow Employee

If you are using custom app which has its own scoping check this link : GlideAjax and AbstractAjaxProcessor


which has how to set up GlideAjax with scoping


Hi Mani, thanks you... yes i saw that and had to modify the line above   "...u_docit_ajax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, ..." to include the global prefix before AbstractAjaxProcessor.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Emyrold,



The error is in this line of code var answer = response.responesXML.documentElement.getAttribute("answer");


should be var answer = response.responseXML.documentElement.getAttribute("answer");


Hi Pradeep,



OMG....   serious type-O...       🙂



Getting closer, but not all the way there yet...   at least I am able to alert(answer) and/or jslog(answer) and see what I am expecting to receive.



The issues is when I go through the glideAjax call it will not set the field, but in the same UI Policy script, if I statically set the same thing and not call the glideAjax that g_form.setValue() works.



Here is my client-side script:


function onCondition() {



  g_form.setMandatory('assigned_to', false);


  g_form.clearValue('assigned_to');


  g_form.setDisplay('assigned_to', false);



  g_form.setValue('assignment_group', 'c0c602364f55d20036988ab18110c7f8', 'SN Developers');   // ****THIS WORKS



  /*     ***** If I comment out this static line above, and then uncomment this GlideAjax block and uncomment the line at the bottom, it does not work.


  var ga = new GlideAjax('u_docit_ajax');


  ga.addParam('sysparm_name', 'getGSDProperties');


  ga.addParam('sysparm_property', 'x_10032_gtd_dev.sn.developers.group');


  ga.getXML(myCallBack);


  */



}



function myCallBack(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  jslog('***Debug_UI_Policy_jslog(): my answer is: ' + answer);



  //g_form.setValue('assignment_group', answer); //answer is coming back is: 'c0c602364f55d20036988ab18110c7f8', 'SN Developers'     ***THIS DOES NOT WORK



}



And here is my current Script Include:


var u_docit_ajax = Class.create();


u_docit_ajax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {


//u_docit_ajax.prototype = Object.extendsObject(x_10032_gtd_dev.u_docit_ajax.AbstractAjaxProcessor, {


// u_docit_ajax.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  /*


  * @getGSDProperties - GlideAjax function called from client script


  * @sysparm_property - This will be the sys_parameter name passed in from the client


  * @returns - The value of the given property


  */



  getGSDProperties: function() {



  var sysProp         = this.getParameter('sysparm_property');


  gs.warn('***DEBUG_Script_Include: gs.getProperty(sysProp) is: ' + gs.getProperty(sysProp));


  sysProp = gs.getProperty(sysProp).toString();


  return sysProp;



  },


  type: "u_docit_ajax"


});



And lastly, here is my error when I uncomment the GlideAjax Block and try to set the field this way:



GlideAjaxError_03.PNG