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

@Ankur Bawiskar I already did it but still not working.

@Ankita Kolhe 

very difficult to troubleshoot without having the instance details.

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

Hello

 

Please share a screenshot of your dictionary with filter Display = true.

 

you're working with a reference field where the "display" field on the referenced table hasn't been properly configured and hence you are getting sysId's.

Nag89
Tera Contributor

Hello @Ankita Kolhe,

 

If getDisplayValue() is returning the sys_id instead of the display value in your Business Rule, it's likely because you're calling it on a field that is a reference field and the field value is not fully populated at the time the Business Rule is executing.

 

This is one of those common issues in before Business Rules where the reference field may not have been fully resolved yet.

 

To resolve this, I'd request you to try using the getDisplayValue() method with an after Business Rule, that should resolve the issue.

 

Else if you want to explicitly use before business rule, then you can load the referenced record first and then get the display value:

 

// Before Business Rule Example
var category = current.category; // Assume category is a reference field
if (category) {
var categoryRecord = new GlideRecord('sc_category');
if (categoryRecord.get(category)) {
var categoryDisplay = categoryRecord.getDisplayValue('name'); // 'name' is the display field
gs.info('Category: ' + categoryDisplay);
}
}

 

I hope this helps. If it helped resolving your issue, please mark it as helpful

Anand Kumar P
Giga Patron
Giga Patron

Hi @Ankita Kolhe ,

 

(function executeRule(current, previous) {

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

    var displayValues = [];

 

    for (var i = 0; i < userList.length; i++) {

        var user = new GlideRecord('sys_user');// you have to replace the table with your glide_list field referring to

        user.addQuery('sys_id', userList[i]);

        user.query();

        if (user.next()) {

            displayValues.push(user.getDisplayValue());

        }

    }

 

    current.field1 = displayValues.join(', ');

})(current, previous);

 

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand