I have a doubt regarding scripting

adlerl
Tera Contributor

My requirement is when user enter user field then Email, manager phn no should auto populate
My qn is here in gr.addQuery('user_name', xyz)
we are getting user ID from client side consider abel.tuter
so then in addQuery we need to write gr.addQuery('user ID', xyz) right ?

The below is my script include
var usergetting = Class.create();
usergetting.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	gettinginfo: function(){
		var xyz = this.getParameter('india');
		var gr = new GlideRecord('sys_user');
		gr.addQuery('user_name', xyz);
		gr.query();
		if(gr.next()){
			return gr.email+"&"+gr.manager+"&"+gr.mobile_phone;
		}
	},
    type: 'usergetting'
});

___________________________________________________________________________

The below code is my client side script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   var ur = g_form.getValue('u_user');
   var ga = new GlideAjax('global.usergetting');
   ga.addParam('sysparm_name', 'gettinginfo');
   ga.addParam('india', ur);
   ga.getXML(pop);

   function pop(response){
	var gettingxmldet = (response.responseXML.documentElement.getAttribute("answer"));
	alert(gettingxmldet);

	var det = gettingxmldet.split("&");
	g_form.setValue('u_email', det[0]);
	g_form.setValue('u_manager', det[1]);
	g_form.setValue('u_phn_no', det[2]);
   }

   //Type appropriate comment here, and begin script below
   
}

 

1 REPLY 1

JenniferRah
Mega Sage

Your code looks pretty good. I think maybe the function within your client script should look like this. You had an additional set of parentheses in the first statement. 

  function pop(response){
	var gettingxmldet = response.responseXML.documentElement.getAttribute("answer");
	alert(gettingxmldet);

	var det = gettingxmldet.split("&");
	g_form.setValue('u_email', det[0]);
	g_form.setValue('u_manager', det[1]);
	g_form.setValue('u_phn_no', det[2]);
   }

 Is it not returning what you need?