The CreatorCon Call for Content is officially open! Get started here.

Get display value field

andresanche
Giga Guru

Using the table API, I am trying to filter my query by a reference display value. 

This is what I originally had in mind:

~/api/now/table/customer_account?sysparm_query=primary_contact.display_value={DisplayValue}

 

Since this doesn't work, I looked into what field is used for display value. I found that the customer_contact table uses the name field, so I changed my query to:

~/api/now/table/customer_account?sysparm_query=primary_contact.name={DisplayValue}

My issue is that all of this needs to happen programmatically. I've been trying to find a table or something that I can pull back from the table API that explicitly states the field used for a references display value. The only thing that I have found to bring back the display fields is:

~/api/now/ui/meta/{table}

This endpoint returns information for each column and the primary_contact reference column for the customer_account table looks like this:

"primary_contact": {
                "filterable": true,
                "reference_display_field": "name",
                "reference_attributes": {
                    "display_field": "name",
                    "ref_ac_columns": [],
                    "ref_ac_columns_search": "",
                    "ref_ac_display_value": true,
                    "ref_auto_completer": ""
                },
                "canmatch": true,
                "cangroup": true,
                "label": "Primary Contact",
                "type": "reference",
                "max_unit": "days",
                "mandatory": false,
                "reference": "customer_contact",
                "default": "",
                "base_type": "GUID",
                "read_only": false,
                "hint": "",
                "name": "primary_contact",
                "attributes": "encode_utf8=false,readonly_clickthrough=true",
                "column_type": "element",
                "internal_type": "reference",
                "cansort": true,
                "max_length": 32
            }

 

 

 
Is there a table with information about the display_field? 

 

Secondary question, the ~api/now/ui/meta endpoint doesn't seem to have documentation. Is it documented?

 

1 REPLY 1

ralvarez
Tera Guru

Hi, you can get it from the Dictionary table:

 

/api/now/table/sys_dictionary?sysparm_query=name={TABLENAME}^display=true&sysparm_fields=element

 

 

However, since a table may extend another, the display field might be defined in one of its ancestors. In that case, you can use this:

 

var queryGen = new GlideCollectionQueryCalculator();
queryGen.buildDictionaryQueryClause(TABLENAME);

For instance, with "incident" as TABLENAME, you get this:

name=incident^ORnameINincident,task

 

Regarding your question about the /api/now/ui/meta/{table} endpoint, it isn’t officially documented in ServiceNow’s REST API documentation. It is primarily used internally by the platform and the UI framework.