- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 01:56 PM
Hello All,
I am currently working on a form where I need to get a sys_user reference and then display the values into string fields on said form.
The following code gets the reference data, but when I set the values into the form, the location and department reference fields place the sys_id into the field.
function onLoad() {
//Type appropriate comment here, and begin script below
var reqName = g_form.getReference('u_reference_1', setEnhUserFields);
}
function setEnhUserFields(reqName) {
g_form.setValue('u_string_3', reqName.user_name);
g_form.setValue('u_string_4', reqName.phone);
g_form.setValue('u_string_5', reqName.email);
g_form.setValue('u_string_6', reqName.department);
g_form.setValue('u_string_7', reqName.location);
}
Is there any way to get the display value of the location and department reference field display values into the string fields on the enhancement? Do I need a script include?
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 02:11 PM
Hello Jason,
You are right. You need to create a script include(client callable set to true) and call it via GlideAjax at the client side. More info here.
http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
At server side, you can use getDisplayValue() to get the display value of the reference field.
http://wiki.servicenow.com/index.php?title=GlideRecord#getDisplayValue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 02:12 PM
You might be able to dot walk to them:
g_form.setValue('u_string_6',reqName.department.name);
g_form.setValue('u_string_7',reqName.location.name);