Value of Parameter getting changed to undefined

Shamma Negi
Kilo Sage
Kilo Sage

I have one select box variable. My requirement is if I select any value in that field I need to restrict the record in Reference field under that.

See the script below:

Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

  if (isLoading || newValue == '') {

  return;

  }

var purpose_change = g_form.getValue('purpose_change');

  var ga = new GlideAjax('CheckProcess ');

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

  ga.addParam('sysparm_purpose_change', purpose_change);

  ga.getXML(handleMessage);

  function handleMessage(response) {

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

  var parentIncidents = answer.evalJSON();

  g_form.clearMessages();

  for (i=0;i< parentIncidents.length;i++){

  g_form.addInfoMessage("Here is an active incident (major or parent): " + parentIncidents[i].number + " with short description: " + parentIncidents[i].short_description);

  }

  }

}

Script Include:

var CheckProcess = Class.create();

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

  checkPurposeofChange: function(checks){

  var sysIDs   = [];

  var checks = this.getParameter('sysparm_purpose_change');

  if(checks == "org_to_temp")

  {

  var gre = new GlideRecord('cmdb_ci_server');

  gre.addEncodedQuery('u_server_sla_exemption=false');

  gre.query();

  while(gre.next()){

  sysIDs.push(gre.sys_id + '');

  }

  return 'sys_idIN' + sysIDs;

  }

  else if(checks == "temp_to_org")

  {

  var grd = new GlideRecord('cmdb_ci_server');

  grd.addEncodedQuery('u_server_sla_exemption=true');

  grd.query();

  while(grd.next()){

  sysIDs.push(grd.sys_id + '');

  }

  return 'sys_idIN' + sysIDs;

  }

  },

  type: 'CheckProcess'

});

Regards,

Shamma

Regards,Shamma Negi
12 REPLIES 12

Use this in your script include and see if it works.   Also in your client script, inside the GlideAjax call, there is an extra space after the script include name, not sure if that makes a difference.


var CheckProcess = Class.create();


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



  checkPurposeofChange: function(){


  var sysIDs   = [];


  var checks = this.getParameter('sysparm_purpose_change');


  if(checks == "org_to_temp")


  {


  var gre = new GlideRecord('cmdb_ci_server');


  gre.addEncodedQuery('u_server_sla_exemption=false');


  gre.query();


  while(gre.next()){


  sysIDs.push(gre.sys_id + '');


  }


  return 'sys_idIN' + sysIDs;



  }



  else if(checks == "temp_to_org")


  {


  var grd = new GlideRecord('cmdb_ci_server');


  grd.addEncodedQuery('u_server_sla_exemption=true');


  grd.query();


  while(grd.next()){


  sysIDs.push(grd.sys_id + '');


  }


  return 'sys_idIN' + sysIDs;



  }



  },



  type: 'CheckProcess'


});


Hi Abhinay,



I tried this as well. It gives me the value of checks "undefined". As I explained above that it is giving the value if checks in logs as org_to_temp but then as soon as I am clicking the reference field it is changing the value to undefined.



This is the issue I am facing.



Regards,


Shamma


Regards,Shamma Negi

Kalaiarasan Pus
Giga Sage

Use a reference qualifier as suggested in the thread. You can access the current value of the variable in the script as



current.variables.variablename