difference between getValue() and setDisplayValue()

22eg105p57
Tera Contributor

Hi everyone,

I’m currently learning ServiceNow and got confused between the usage of getValue() and getDisplay() methods in scripts.

Can someone clearly explain:

What is the difference between getValue() and setDisplayValue()?

Thanks in advance!

1 ACCEPTED SOLUTION

prerna_sh
Giga Sage

Hi @22eg105p57 ,

 

getDisplayValue() is used to retrieve the displayed (user-friendly) value of a field. For example, if you're working with a reference field like "assigned_to", this method will return the user's name.

getValue(), on the other hand, retrieves the actual stored value in the database, which may differ from the display value. For reference fields, it typically returns the Sys ID or a unique value.

setDisplayValue() method sets the value of a reference field by using its display value (e.g., a user's name instead of their sys_id).

For Better understanding please go through: How to use getDisplayValue() and getValue() for ... - ServiceNow Community

If my response solves your query, please marked helpful by selecting Accept as Solution and Helpful. Let me know if anything else is required.
Thanks,
Prerna

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@22eg105p57 

answer to your question is easily available on google, docs etc

You could have searched that to save time

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

AndersBGS
Tera Patron
Tera Patron

Hi @22eg105p57 ,

 

getValue() will the "real" value of the field where getDisplayValue() will get the displayed value instead - e.g. not SysID for reference fields.

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

prerna_sh
Giga Sage

Hi @22eg105p57 ,

 

getDisplayValue() is used to retrieve the displayed (user-friendly) value of a field. For example, if you're working with a reference field like "assigned_to", this method will return the user's name.

getValue(), on the other hand, retrieves the actual stored value in the database, which may differ from the display value. For reference fields, it typically returns the Sys ID or a unique value.

setDisplayValue() method sets the value of a reference field by using its display value (e.g., a user's name instead of their sys_id).

For Better understanding please go through: How to use getDisplayValue() and getValue() for ... - ServiceNow Community

If my response solves your query, please marked helpful by selecting Accept as Solution and Helpful. Let me know if anything else is required.
Thanks,
Prerna