Need a simple and clear answer!

PP12
Giga Contributor

Q.1) What is the use of getValue() and getDisplayValue()  and when do we use it exactly?

Q.2) What is the difference between getValue() and getDisplayValue() ?

Q.3) What is the use of setValue() and setDisplayValue()  and when do we use it exactly?

Q.4) What is the difference between getValue() and setDisplayValue() ?

 

I want to clear my confusion permanently:-/

 

 

4 REPLIES 4

ServiceNowSteve
Giga Guru

Some fields like reference fields and choice lists have a name and a value. For example if you have a reference field to a user table the name might be "Abel Tutor" but the value is the sys_id of 1234567890acbde.

So to answer your question directly.

 

1 and 2 -  getValue get's the value of that record (In the above case the sys_id) where as getDisplayValue will get the name

3 and 4 - Same thing for set, this is particularly useful for setting a reference field because you may have 2 or more "Abel Tutor" names in your company but the sys_id is unique.

vinothkumar
Tera Guru

getValue is used to get the actual value and it will be mostly used in single line text, string etc. where as getDisplayValue is used to get the display value and this is normally used, whenever the variable or field is referring to the values in the different table. Normally for example you have a reference field which is pointing to group table and it will be having group name , but if you put getValue() method to retreive that value, it will provide a sys_id, because it is just reference to another table and if you want to get the actual name then getDisplayValue.

 

Where as for string, the value it is holding in the front end and backend are same, it will provide the value if u r using just getValue() itself. Similarly if you want to set values, you have to use setValues

PP12
Giga Contributor

Can we use getDisplayValue and setDisplayValue in Client side?

 

can you give a short code for setDisplayValue? just for example

Community Alums
Not applicable

Hi,

my suggestion. 

If you want simple and clear to learn, it is always good practice to learn from the developer guide. As the question you have asked is more related to fundamentals of using the element functions. 

https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GlideFormGetValue_String --getValue()

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-getDisplayValue -- getDisplayValue()

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GlideRecord-setDisplayValue_String_Object -- setDisplayValue()

https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_GlideElement-setValue_Object --setValue()


Please mark the answer helpful or correct based on the impact of the response. 

Thanks
Ishan Parikh