get the display value of the reference field

dev_K
Tera Contributor

Hi All,

 

 

 

I have a catalog item where I use a reference field and a text field.

I would like the text field to have the exactly the same value as the reference field:

 

dev_K_2-1727689376502.png

 

 

this works on the backend with the following client script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var groupDisplayValue = g_form.getDisplayBox('group').value;

    // Set the 'group_name' field to the display value of 'group'
    g_form.setValue('group_name', groupDisplayValue);
}

 

 

 

This does not work in ESC as I am getting a JS error that getDisplayBox() doesnt work.

 

dev_K_0-1727689319461.png

 

dev_K_1-1727689332956.png

 

 

 

I tried to use the 'getDisplayvalue()' instead but it does not work

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@dev_K getDisplayBox doesn't work in case of Service Portal. You can get the display value via one of the following approaches.

 

1. GlideAjax: Make a server side script include method call using GlideAjax. This method should accept the sys_id of the assignment group as input and should return the display value/name of group based on sys_id

2. g_form.getReference: Make a g_form.getReference('<field_name>',callaback); method call and fetch the value of assignment group name field.

 

Hope this helps.

Anurag Tripathi
Mega Patron
Mega Patron

On client side you can use the script below to get Display value of reference field

g_form.getDisplayBox('<field name>').value;

Hi,

 

-Anurag