We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Value return error in widget

KiranmaiP
Tera Contributor

Can we add getValue() with field value of type "String"?

Is it getDisplayValue() or getValue()?

1 ACCEPTED SOLUTION

_Tushar Soni
Kilo Sage

Hello @KiranmaiP ,

Yes, you can use getValue() with a field of type String.

 

getValue() - Retrieves the actual value stored in the database
Example: When you need the raw data, like a sys_id or the exact value of a field.
var fieldValue = g_form.getValue('field_name');

 

getDisplayValue() - Retrieves the human-readable or display value that users see.
When you need the name, label, or description that is shown in the UI, especially for reference fields.

var displayValue = g_form.getDisplayValue('field_name');

 

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!

View solution in original post

2 REPLIES 2

_Tushar Soni
Kilo Sage

Hello @KiranmaiP ,

Yes, you can use getValue() with a field of type String.

 

getValue() - Retrieves the actual value stored in the database
Example: When you need the raw data, like a sys_id or the exact value of a field.
var fieldValue = g_form.getValue('field_name');

 

getDisplayValue() - Retrieves the human-readable or display value that users see.
When you need the name, label, or description that is shown in the UI, especially for reference fields.

var displayValue = g_form.getDisplayValue('field_name');

 

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!

Pratiksha_kadam
Tera Contributor

Hi Varun,

 

Please go through  this article: https://www.servicenow.com/community/in-other-news/how-to-use-getdisplayvalue-and-getvalue-for-glide...

I hope this will help you.

Please mark helpful if I answered correctly.