- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 05:59 AM
Good Day everyone,
i created a catalog item that is used for internal changes to an employee.
In my form i have a reference field linked to the sys_user table and when you choose a person their information will get populated into single text fields via a client script.
What is happening, the person Manager (linked to the sys_user table) and their Location(linked to the cmn_location table) is only coming back with the Sys_ID as seen below:
The script i am using is the following:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:08 AM
I was able to figure it out,
here is the updated code for anyone to use.....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:38 AM
Try this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userDetails = g_form.getReference('preferred_name', myFunc);
function myFunc(userDetails){
var loc = new GlideRecord('cmn_location');
loc.addQuery('sys_id', userDetails.location);
loc.query(getLocation);
function getLocation(loc){
loc.next();
var man = new GlideRecord('sys_user');
man.addQuery('sys_id', userDetails.manager);
man.query(getManager);
function getManager(man){
man.next();
g_form.setValue('current_title', userDetails.title);
g_form.setValue('current_persona', userDetails.u_persona);
g_form.setValue('current_share_team', userDetails.u_share_team);
g_form.setValue('current_department', userDetails.department);
g_form.setValue('current_office_workstation_id', userDetails.u_desk_location);
g_form.setValue('current_location', userDetails.location, loc.name);
g_form.setValue('current_phone_number', userDetails.phone);
g_form.setValue('current_manager', userDetails.manager, man.u_preferred_name);
}
}
}
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:11 AM
Hi @Peter Williams,
Have you checked the result of that? You are now setting the display value as value. So it looks ok, but you do not have any reference.
Please look at my latest answer for the solution that should work.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:27 AM
New issue, it doesnt work in the Service Portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:31 AM
Since your screenshot was backend, I did not take portal into account.
.get does not work in Service Portal, so you are going to do a asynchronous call to the manager and location records to get the display values.
Rest of the script should still work.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:37 AM
doesnt seem to work, here is the code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2023 07:38 AM
Try this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userDetails = g_form.getReference('preferred_name', myFunc);
function myFunc(userDetails){
var loc = new GlideRecord('cmn_location');
loc.addQuery('sys_id', userDetails.location);
loc.query(getLocation);
function getLocation(loc){
loc.next();
var man = new GlideRecord('sys_user');
man.addQuery('sys_id', userDetails.manager);
man.query(getManager);
function getManager(man){
man.next();
g_form.setValue('current_title', userDetails.title);
g_form.setValue('current_persona', userDetails.u_persona);
g_form.setValue('current_share_team', userDetails.u_share_team);
g_form.setValue('current_department', userDetails.department);
g_form.setValue('current_office_workstation_id', userDetails.u_desk_location);
g_form.setValue('current_location', userDetails.location, loc.name);
g_form.setValue('current_phone_number', userDetails.phone);
g_form.setValue('current_manager', userDetails.manager, man.u_preferred_name);
}
}
}
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.