"display_value" missing in API call...

amiller24
Tera Contributor

I'm making a Table API call to my instance and specifically setting sysparm_display_value=all so that I get the value and display value for all the properties on the record I am retrieving...  Unfortunately, for some properties the JSON being returned (I can't determine a pattern of why some do and some don't) exclude "display_value" which results in my program thinking the value is null when the "value" is "" (which is a blank and not technically null).

Does anyone know why it seems like ServiceNow randomly decides when it's going to return a display value or not?  Here are some examples from a call against the incident class on my instance...  Close Code and Timeline did not return "display_value" but sys_tags and Parent Incident did...  So even though sys_tags and Parent Incident as "", their display value is still obtained and saved as "" on my side whereas both Close Code and Timeline also have a value of "" but since there is not a display value in the JSON, they are saved as null on my side...

"close_code": {
"value": ""
}

"sys_tags": {
"display_value": "",
"value": ""
}

"timeline": {
"value": ""
}

"parent_incident": {
"display_value": "",
"value": ""
}

I know I could do some hard coding to handle these situations but I'm trying NOT to modify the data in anyway so I can record it as it is in ServiceNow...  Any thoughts on the inconsistency?

1 ACCEPTED SOLUTION

M Iftikhar
Mega Sage

Hello amiller,

This is a common behavior in ServiceNow's Table API. The display_value field only appears in the response when:

  1. Reference Fields: For reference fields (like parent_incident), ServiceNow provides display_value to show the display name of the referenced record.

  2. Choice Fields: For choice fields (like close_code), display_value shows the label while value shows the actual stored choice value.

  3. Empty Non-Reference Fields: For string fields like timeline and sys_tags, when the value is empty, ServiceNow often omits the display_value entirely since it would be identical to the empty value.

The pattern you're observing is expected - reference fields get display_value even when empty, while standard string fields may not.

Workaround Suggestions:

  • Check the field type in your instance's dictionary for each field

  • Implement logic to handle cases where display_value is missing

  • Consider using sysparm_display_value=true instead of all for consistent behavior

This inconsistency is by design based on field types and their content.

 

Hope this helps!

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it helpful & accept the solution so others can benefit as well.

View solution in original post

3 REPLIES 3

DrewW
Mega Sage

This ones that are not sending display value are probably string fields. So in javascript could check for this by doing something like the below.

var valueToUse = "";
if(obj.field.display_value) {
   valueToUse = obj.field.display_value;
} else {
   valueToUse = obj.field.value;
}

 

amiller24
Tera Contributor

Thank you for the code sample.  I was afraid I'd have to do this, but it is what it is.

M Iftikhar
Mega Sage

Hello amiller,

This is a common behavior in ServiceNow's Table API. The display_value field only appears in the response when:

  1. Reference Fields: For reference fields (like parent_incident), ServiceNow provides display_value to show the display name of the referenced record.

  2. Choice Fields: For choice fields (like close_code), display_value shows the label while value shows the actual stored choice value.

  3. Empty Non-Reference Fields: For string fields like timeline and sys_tags, when the value is empty, ServiceNow often omits the display_value entirely since it would be identical to the empty value.

The pattern you're observing is expected - reference fields get display_value even when empty, while standard string fields may not.

Workaround Suggestions:

  • Check the field type in your instance's dictionary for each field

  • Implement logic to handle cases where display_value is missing

  • Consider using sysparm_display_value=true instead of all for consistent behavior

This inconsistency is by design based on field types and their content.

 

Hope this helps!

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it helpful & accept the solution so others can benefit as well.