Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

The SN Nerd
Giga Sage
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.

 


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

7 REPLIES 7

SatheeshKumar
Kilo Sage

yes ,we have current.getDisplayValue('assigned_to'); it won't throw error even when the field is empty!!

 

 

 

Hi. Thank you for your reply.
I understand that you don't throw errors in the way you wrote.
Sorry, But the usage of "current.getDisplayValue ('assigned_to')" is not officially documented, so we can't determine if it's the correct method.

Is there a document that can be recognized as an official usage?

I can't find any official document for this!!.

Haha ..!! Most of the service portal methods are not officially documented by servicenow but we are still using them 🙂

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can check whether field is valid or not before using this

var isValid = current.isValidField(<FieldName>);

if(isValid){

current.<FieldName>.getDisplayValue();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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