Populate location based on caller's field

renu8
Giga Contributor

I tried populating location field using g_form.getReference() it worked. but I am not able to achieve it using GlideAjax. Kindly help.

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Did this work for you? Still any questions? Could you please update. I do see you are posting other questions again. So please resond to the topics your posting and where people are responding to.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

17 REPLIES 17

Service_RNow
Mega Sage

HI,

please try code:-

SI:-

var reuestedutil = Class.create();
reuestedutil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	//type: 'reuestedutil':
	myFunction: function()
	{
		var ab=this.getParameter('sysparm_var');
		var gr=new GlideRecord("sys_user");
		gr.addQuery('sys_id',ab);
		gr.query();
		if(gr.next())
			{
			var fname=gr.first_name;
			var email=gr.email;
			var phone=gr.mobile_phone;
			var loc=gr.location.getDisplayValue();
			return fname +'||'+ email +'||'+ phone +'||'+ loc;
		}
		
		
	}
	
});

SC Client Script:-

var ga =new GlideAjax("reuestedutil");
	ga.addParam('sysparm_name','myFunction');
	ga.addParam('sysparm_var',newValue);
	ga.getXMLAnswer(getValue);
	function getValue(response)
	{
		var ans=response;
		var gh=ans.split("||");
		g_form.setValue("name",gh[0]);
		g_form.setValue("email",gh[1]);
		g_form.setValue("phone",gh[2]);
		g_form.setValue("location",gh[3]);
		
	}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy.

Thanks,

Mark Roethof
Tera Patron
Tera Patron

Did this work for you? Still any questions? Could you please update. I do see you are posting other questions again. So please resond to the topics your posting and where people are responding to.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hiteish222
Kilo Guru

Hi,

use below code with onChange Client script,

function onChange(control, oldValue, newValue, isLoading) {
var getLocation=g_form.getReference('caller_id', LocationData); 
}
 function LocationData(getLocation) { // reference is passed into callback as first arguments
 g_form.setValue("location",getLocation.location);
}