On change client script issue for reference variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 02:54 PM
We have a table (cmdb_ci_appl) where there is no Display value.
we have a catalog item in which we have a reference field, on selecting the 1st field we need to populate the 3 other fields.
How to set the app ID ( which is highlighted) upon selecting? ( as of now it is defaulting to name , which is on the left side)
Below is the Onchange CS script ( for some reason when the ID is selected it is not setting the name in the name field (name is of string type on the table )
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var AppID = g_form.getReference('citrix_application_id', SetApplicationvariables);
function SetApplicationvariables(AppID) {
g_form.setValue('citrix_application_name', AppID.name);
g_form.setValue('citrix_application_version', AppID.version);
g_form.setValue('citrix_application_vendor_name', AppID.u_common_name);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 03:21 PM
First... the Display Value piece. Even if a table does not have a field designated, ServiceNow uses the following sequence to determine a display value:
- A field with display=true in the system dictionary on the lowest sub-table for extended tables.
- A field with display=true in the system dictionary on the parent table.
- A field named name or u_name.
- The Created on field of the referenced record.
Secondly, you are getting a GlideRecord for the AppID and accessing GlideElement objects for the field assignments. Try explicitly converting the GlideElements to string before setting the value:
g_form.setValue('citrix_application_name', AppID.name + '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 03:39 PM
For the display value piece, is there a way to solve this by adding any script? without changing or setting the display value?
I tried replacing the line with yours but still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2022 11:23 PM
Hi,
if you don't set any field as Display=True then ServiceNow shows/follows the sequence mentioned by John
script looks fine to me
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
07-05-2022 10:44 AM
Can we set that via attributes? as of now I am using the below in the attribute section
ref_ac_columns_search=true,ref_auto_completer=AJAXTableCompleter,ref_ac_columns=u_number,ref_ac_display_value=false