Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Variable set catalog client script is not working

suryareddyn
Giga Expert

I have created variable set ,wrote a script in catalog script and it is not working in service portal. Simple alert is not working. Please guide me If I need to make any changes global to work client script in service portal?

T1.png.

1 ACCEPTED SOLUTION

Well, it is working fine on my end. Try this, using a callback function



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


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


  return;


  }


  var gp = new GlideRecord('core_country');


  gp.addQuery('name', newValue);


  gp.query(callBack);



  alert('working');


  function callBack(gp){


  while(gp.next()){


  countrycode = gp.iso3166_3;


  alert('test');


  }


  }


  //Type appropriate comment here, and begin script below



}


View solution in original post

28 REPLIES 28

Did you try using using a callback function as mentioned above?


Call back is working.


Abinay, Thanks a lot.



If I try to alert countrycode outside while loop, its pop up wrong value.



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


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


  return;


  }


  var gp = new GlideRecord('core_country');


  gp.addQuery('name', newValue);


  gp.query(callBack);




  function callBack(gp){


  while(gp.next()){


  countrycode = gp.iso3166_3;



  }


  }



alert(countrycode);




}


Abhinay Erra
Giga Sage

You need to put alert inside the callback function. Otherwise it will not work. Please mark my response as correct.


suryareddyn
Giga Expert

Abinay,



I have to call one more table to fetch the data and the alert (test1) is not working . Please help me?



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


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


  return;


  }


  var gp = new GlideRecord('core_country');


  gp.addQuery('name', newValue);


  gp.query(callBack);




  function callBack(gp){


  while(gp.next()){


  countrycode = gp.iso3166_3;



  // get locations using country from the u_citrix_office_locations name


  var gp1 = new GlideRecord('u_citrix_office_locations');


  gp1.addQuery('u_country_code', countrycode);


  gp1.query();


  while(gp1.next()){


  alert('test1');


  var location = gp1.u_address_1;


  location += " , "+gp1.u_address_2;


  location += " , "+gp1.u_building_name;


  g_form.addOption('vs_location', gp1.u_address_1, location);



  }



  }


  }



}