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

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi RudhraKAM

Screen image is missing from the question. It is no longer possible to paste a image. It is necessary to save the image to a file in local pc and then upload the file.
 
Anyways, as others have already replied, I have been able to run the script and the fields were filled (except for citrix_application_vendor_name which is a custom field). Not sure why it's not working in your instance without further details.
 
As stated in the question, there is no display=true field in table cmdb_ci_appl.
find_real_file.png

I've defined variables as below.

find_real_file.png

Executed the form. Selecting item in citrix_application_id field filled other fields.

find_real_file.png

If using the single-line text variable it is working but the requirement is for the application name should be reference field. and the name is not populating ( the variable is mandatory ) on change it is setting to something but it is not displaying , i say this because mandatory is off  on change.

Field "Name" is a String in table cmdb_ci_appl

find_real_file.png