- 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:51 PM
Hi,
can you share what came in alert for answer?
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:55 PM
Hi,
The alert getting like "null, null"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 10:05 PM
Hi Siva,
is the script include client callable?
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 10:07 PM
yes ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 10:09 PM
please share script include and client script screenshot
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader