Why getDisplayValue() displaying sys_id instead of value for glide list type field?

Ankita Kolhe
Tera Contributor

Hi Community,

I have a glide list type field and I want to copy display value of that field to another field of string type.

 

I created a before- insert/update Business rule for the same with below code:

 

current.field1=current.field2.getDisplayValue();

gs.addInfoMessage(current.field1);

 

The above info message is displaying sys id instead of value.

 

Please someone help on this.

 

Thanks

30 REPLIES 30

Runjay Patel
Giga Sage

Hi @Ankita Kolhe ,

 

The issue arises because getDisplayValue() for a Glide List field returns the raw sys_id values, not the display value of the related records. To fetch the actual display values of a Glide List field, you need to query the related records and concatenate their display values.

 

 

var glideListSysIds = current.field2.split(',');

    // Query the related records in the referenced table
    var gr = new GlideRecord('referenced_table'); // Replace with the actual table name
    gr.addQuery('sys_id', 'IN', glideListSysIds);
    gr.query();
    while (gr.next()) {
        // Add the display value of each record to the array
        gs.addInfoMessage(gr.getDisplayValue());
    }

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------