- 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: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-18-2017 12:20 PM
Let me know if that answered your question. If so, please mark it as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-18-2017 12:28 PM
Pradeep,
What I did was change the target fields from string fields to reference fields for their respective tables. When the code
var reqName = g_form.getReference('u_reference_1', setEnhUserFields);
fetches the user data record, it also gets the reference field information.
The fields now display the referenced display data. Not the "best practice" method, but it works for my needs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2017 11:39 AM
The ServiceNow Wiki content is no longer supported. Updated information about this topic is located here: AJAX
GlideRecord
Visit http://docs.servicenow.com for the latest product documentation