Script include for service catalog

UmeshGowda
Tera Contributor

Hello Team,

 

Am trying to auto populate user location in service catalog using script include method and client script, when ever am selecting username.

 

 

Below is the client script i have written:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
 
var ga = new GlideAjax('LocationDetails');
ga.addParam('sysparm_name','getLocation');
ga.addParam('sysparm_value',g_form.getValue('user_name'));
ga.getXML(test);
 
function test(res){
 
var answer = res.response.documnetElement.getAttribute("answer");
alert(answer);
 
}
   
}
 
Below is the script include i have written :
 
var LocationDetails = Class.create();
LocationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
getLocation: function(){
 
var loc = this.getParameter('sysparm_value');
var x =new GlideRecord('sys_user');
x.addQuery('sys_id', loc);
x.query();
if(x.next()){
gs.log('location is ',+x.location);
return x.location;
}
 
},
    type: 'LocationDetails'
});
 
But unfortunately, when am selecting username it's not auto populating user location filed, can someone please suggest me.
8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Are you getting this log?

gs.log('location is ',+x.location);

-Anurag

No i don't no see any log its creating.

Add an Alert on the client script 

alert(g_form.getValue('user_name'));

-Anurag

 
Please let me know is it the right place where i have added alert?
 
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
 
var ga = new GlideAjax('LocationDetails');
ga.addParam('sysparm_name','getLocation');
ga.addParam('sysparm_value',g_form.getValue('user_name'));
alert(g_form.getValue('user_name'));
ga.getXML(test);
 
function test(res){
 
var answer = res.response.documnetElement.getAttribute("answer");
alert(answer);
 
}
   
}