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

The value of checks   is showing as undefined in script include. However when I put alert in client script it is showing me the correct value. I put alert for the value of var purpose_change = g_form.getValue('purpose_change');.



Hope you got my point.



Regards,


Shamma


Regards,Shamma Negi

Hi Shamma,



Important note, script includes are run on the server side. g_form is a client script construct. That could be part of the issue. You might find episodes 4, 5 and 6 in the list below quite helpful.



TechNow Episode List


Hi chuck,



I am not using the g_form in the script include as I know they run on server side. I am using it in my client script.



Request you to please check the code which I mentioned in my first post.



Please suggest.



Regards,


Shamma


Regards,Shamma Negi

Are you using the same code that is mentioned in this post?


yes The code I mentioned in the first post


Regards,Shamma Negi