- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 09:03 PM
Hi,
Get user location and it region with script include call through the client script,
I wrote the both script include and client script, but didn't get results, Its getting null alert. Can u please check my code and attachement
script include:
var reqtest = Class.create();
reqtest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
//Get the sys_ID for the call
//pass the input
var callerSysID = this.getParameter('sysparm_callerSysID');
//glide the user table for fetching the records
var gr = new GlideRecord('sys_user');
gr.get(callerSysID);
var mgr = gr.getValue('u_emploment_counrty.u_it_region');
var loc = gr.getValue('location');
var arr = []; // define the array
arr[0] = mgr; //set the manager in the array
arr[1] = loc; //set the location in the array
return JSON.stringify(arr);
},
type: 'reqtest'
});
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
client script:
var callerSysID = g_form.getValue('caller_id'); //push the sysID of the caller record
var ga = new GlideAjax('reqtest'); //call the script include
ga.addParam('sysparm_name','getDetails'); // call the function of include
ga.addParam('sysparm_callerSysID', callerSysID); //pass the fetched call sys_id in the include
ga.getXML(handleResponse);
function handleResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer"); //fetch the response from script include
var answers = answer.evalJSON(); //evaluate the response and decode it
alert(answer);
g_form.setValue('u_region',answers[0]); //set the short description
g_form.setValue('location',answers[1]); //set te description
}
}
Thank you
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 10:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 10:43 PM
Hi,
you did not copy script include correctly
remove everything from script and add this again and save
var reqtest = Class.create();
reqtest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var callerSysID = this.getParameter('sysparm_callerSysID');
var gr = new GlideRecord('sys_user');
gr.get(callerSysID);
var mgr = gr.u_emploment_counrty.u_it_region.toString();
var loc = gr.getValue('location');
var obj = {}; // define the array
obj["mgr"] = mgr; //set the manager in the array
obj["loc"] = loc; //set the location in the array
return JSON.stringify(obj);
},
type: 'reqtest'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2022 12:05 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
If not, please let us know if you need some more assistance.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2022 07:50 AM
Hi I used this code for get location from requested by on change form and then set the location on work notes when requested by change . but return the sys_id . not the location. can you help me to this please

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 09:22 PM
Hi there,
Add some debugging to your code. This will quickly identify up to where your code is working, variables hold values you would expect, etc.. With this, you will identify within seconds where to look at, instead of spending hours on this.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video 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
01-12-2022 09:23 PM
Because you are trying to set reference fields with this client script, do also read and apply:
2020-10-19 setValue() reference fields/variables, use the value AND displayValue parameter
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, video 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
01-12-2022 09:26 PM
Hi,
you are forming array and then converting it to json string; don't do that
Also don't use evalJSON
please try this and share the update
Script Include:
var reqtest = Class.create();
reqtest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function() {
var callerSysID = this.getParameter('sysparm_callerSysID');
var gr = new GlideRecord('sys_user');
gr.get(callerSysID);
var mgr = gr.u_emploment_counrty.u_it_region.toString();
var loc = gr.getValue('location');
var obj = {}; // define the array
obj["mgr"] = mgr; //set the manager in the array
obj["loc"] = loc; //set the location in the array
return JSON.stringify(obj);
},
type: 'reqtest'
});
Client Script:
var callerSysID = g_form.getValue('caller_id'); //push the sysID of the caller record
var ga = new GlideAjax('reqtest'); //call the script include
ga.addParam('sysparm_name','getDetails'); // call the function of include
ga.addParam('sysparm_callerSysID', callerSysID); //pass the fetched call sys_id in the include
ga.getXML(handleResponse);
function handleResponse(response){
var answer = response.responseXML.documentElement.getAttribute("answer"); //fetch the response from script include
var parsedData = JSON.parse(answer); //evaluate the response and decode it
g_form.setValue('u_region',parsedData.mgr); //set the short description
g_form.setValue('location',parsedData.loc); //set te description
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 09:36 PM
Hi ankur,
Thank you for your reply,
I am using your code, But i didn't get result, can u please help me on that.
Thank you.