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

Lookup.png


GlideRecord queries are not recommended on client side. But your code looks good. Try alerting the newValue and see what it shows



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



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


          return;


    }


    g_form.clearOptions('vs_location');


alert(newValue);


  var countrycode;


  // Get the country code from country table


  var gp = new GlideRecord('core_country');


  gp.addQuery('name', newValue);


  gp.query();



        alert('working');



  while(gp.next()){


    countrycode = gp.iso3166_3;


  alert('test');


  }


}


Abinay,


Pop up shows Country name


T5.png


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



}


Is there any alternative for GlideRcord ? Do you have sample code to fetch data from the database ?