Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get display field

andresanche
Giga Guru

Using the table API, I am trying to filter on a reference display_value. I thought it would work like:

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

To make this filter work, I realized I needed to use the column the display_value is derived from which for the customer_contact table that would be name. Working query below:

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

 

My issue is that I want to find the column that the display value comes from programmatically to do this for multiple tables. Is there a table that holds information regarding what column/field is used for the display value?

The only thing I have found to return this type of information is:

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

Using this endpoint for customer_contact and looking at the primary_contact column, I found the display_field is name. Result below:

"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
            }

This endpoint returns display_field for references, which could solve my issue, but I would prefer to get this information from a table. 



 

0 REPLIES 0