- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:34 PM
Hello all,
I have a catalog item im working on where im trying to populate some information based on the user in the requested for field, things are working except the location field and the manager field, can anyone spot what is wrong with my client script?
Client script: onChange
Variable name: requested_for
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var empInfo = g_form.getReference('requested_for', userDetails);
function userDetails(empInfo){
g_form.setValue('employee_number', empInfo.user_name);
g_form.setValue('job_title', empInfo.title);
g_form.setValue('location', empInfo.location.name);
g_form.setValue('manager_name', empInfo.manager.name);
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:41 PM
You can't do dot walking using getreference.
So your script should be
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var empInfo = g_form.getReference('requested_for', userDetails);
function userDetails(empInfo){
g_form.setValue('employee_number', empInfo.user_name);
g_form.setValue('job_title', empInfo.title);
g_form.setValue('location', empInfo.location);
g_form.setValue('manager_name', empInfo.manager);
}
}
And you variables should be reference fields. So location should be a reference field to cmn_location and manager should be a reference field to sys_user.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:40 PM
You cannot dot walk in client script you will have to use GlideAJAX to process this on server side and return results.
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Call the GA function
var ga = new GlideAjax('u_userInfoAjax');
ga.addParam('sysparm_name', "getInfo");
ga.addParam('sysparm_user', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(answer){
// Save the return to a global variable
var info = JSON.parse(answer);
g_form.setValue('location', info.location);
g_form.setValue('manager_name', info.manager);
g_form.setValue('employee_number', info.user_name);
g_form.setValue('job_title', info.title);
});
}
Script Includes
var u_userInfoAjax = Class.create();
u_userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var user = this.getParameter('sysparm_user');
var gr = new GlideRecord("sys_user");
gr.get(user);
var location = gr.location.name;
var manager = gr.manager.getDisplayValue();
var title = gr.title;
var user_name = gr.user_name;
var response = {};
response.location = location;
response.manager = manager;
response.title = title;
response.user_name = user_name;
return JSON.stringify(response);
},
type: 'u_userInfoAjax'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:57 PM
Would this still work in the service portal?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 04:09 PM
Yes, It will work everywhere.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2019 03:41 PM
You can't do dot walking using getreference.
So your script should be
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var empInfo = g_form.getReference('requested_for', userDetails);
function userDetails(empInfo){
g_form.setValue('employee_number', empInfo.user_name);
g_form.setValue('job_title', empInfo.title);
g_form.setValue('location', empInfo.location);
g_form.setValue('manager_name', empInfo.manager);
}
}
And you variables should be reference fields. So location should be a reference field to cmn_location and manager should be a reference field to sys_user.
Please mark this response as correct or helpful if it assisted you with your question.