how to get display value?

sakata kenichi
Kilo Contributor

The official reference does not specify any arguments for the getDisplayValue () method.

Therefore, I think the usage of current. <FieldName> .getDisplayValue () is correct,

At this time, an error will occur if fieldName does not exist.

It is hard to check the existence of fieldName every time.

Is there a way to get a displayvalue that works even if fieldName doesn't exist, like current.getValue ("fieldName")?

 
1 ACCEPTED SOLUTION

paulmorris
Giga Sage

You can use the following function in Global as an alternative to getDisplayValue()

var value = gs.getDisplayValueFor(current.getTableName(),current.getValue('sys_id'),'number');

GlideSystem.getDisplayValueFor() | ServiceNow Legacy API

This will return the display value or null if the field does not exist.

 

View solution in original post

7 REPLIES 7

paulmorris
Giga Sage

You can use the following function in Global as an alternative to getDisplayValue()

var value = gs.getDisplayValueFor(current.getTableName(),current.getValue('sys_id'),'number');

GlideSystem.getDisplayValueFor() | ServiceNow Legacy API

This will return the display value or null if the field does not exist.

 

Hi. Thank you for your reply.

It is “Legacy API”...?
What is the difference from “SCOPED API”?

paulmorris
Giga Sage

Don't let the name "legacy" scare you - it is just what ServiceNow call it in their documentation.

If you are developing in an Application Scope, you must refer to the Scoped API, as some global functions are not available.

More about Scoped API here.