Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

On change client script issue for reference variable

RudhraKAM
Tera Guru

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);

    }

}

 

 

12 REPLIES 12

John Dahl
Kilo Sage

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:

  1. A field with display=true in the system dictionary on the lowest sub-table for extended tables.
  2. A field with display=true in the system dictionary on the parent table.
  3. A field named name or u_name.
  4. 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 + '');

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.

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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