Why getDisplayValue() displaying sys_id instead of value for glide list type field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 09:37 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 11:38 PM
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
-------------------------------------------------------------------------
