- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2020 04:50 AM
I tried populating location field using g_form.getReference() it worked. but I am not able to achieve it using GlideAjax. Kindly help.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2020 06:08 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2020 06:03 AM
Where are you trying this? On incident form or catalog item (or record producer)?
If catalog form or record producer then its fine but if its on incident form then I would recommend using the dot-walked location field (via caller field on incident) on the form.
Doing this will always show you current location of the caller without any script and you dont have to maintain it as well.
To do this right click on incident form header > configure > form layout > add Caller.Location field on the form.
In case you want location field on the incident to be location of the caller when he raised an incident then write a before insert business rule to copy it from callers location.
-Tanaji
Please mark response correct/helpful if applicable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2020 06:06 AM
Just to let you know in case you are new to ServiceNow-
Even getReference() is fine if you are using it will callback function.
It might take a bit more time then GlideAjax but then reduces code complexity.
-Tanaji
Please mark response correct/helpful if applicable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2020 07:29 AM
Hi Renu,
I have done your use case. Try Below code
OnChange() Client Script on Caller Field in incident form
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('getLocation');
ga.addParam('sysparm_name','getloc');//getloc is function name in Script include
ga.addParam('sysparm_caller',newValue);//pass caller name from client script to script include(newValue is caller)
ga.getXMLAnswer(callback);
function callback(response)
{
var answer = response;
alert("location"+answer);//Location is return
}
}
Script Include that will return Caller location
var getLocation = Class.create();
getLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getloc: function() {
//var caller = this.getParameter('sysparm_caller');
// gs.addInfoMessage("caller in SI=" +caller);
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id",this.getParameter('sysparm_caller'));
gr.query();
while (gr.next())
{
return gr.location.name.toString();
}
},
type: 'getLocation'
});
I hope it will definitely help you.
Please Mark it Correct/Helpful answer if it help you in any way.
Thanks and Regards,
Kunal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2020 11:28 AM
Thank you. Can you please help me to understand when do we use getXMLAnswer() and when do we go for getXML(). I tried referring the previous articles but it's not properly explained.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2020 11:33 AM
Check these two pages. Async and Sync GlideAjax both are explained with examples.
Synchronous GlideAjax-
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference...
Asynchronous GlideAjax-
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference...
-Tanaji
Please mark reply correct/helpful if applicable