GET operation via REST API - Can I return reference field not sys_user GUID or display value?

chrisfowells
Kilo Contributor

When performing a GET operation you should have the option of what field/s to return for a reference, i.e. instead of just either the GUID, or the Display Value but any field from the referenced table. For instance if you've added a reference to a user to a table from the sys_user table (e.g. adding an owner of an application to an application table) and when you retrieve the data via a Rest API, for the reference field you might not want either the sys_user GUID, or the display value, but the NT_ID.

5 REPLIES 5

Jon Barnes
Kilo Sage

are you using the table API? You can use dot-walked fields there, like user.u_nt_id or something to that effect. So in the fields parameter, pass in user.u_nt_id and you will get that back in the result, assuming your reference field is called "user".


@Jon Barnes - is there a way to get the value of u_nt_id nested within the user object in the response? Something like - 

Instead of the response being 
{
 "user.u_nt_id" = "some_id"
}
Can we get something like - 
{
 "user": {
    "u_nt_id" = "some_id"
  }
}

Hitoshi Ozawa
Giga Sage
Giga Sage

If it is a new proposal and not a question, it would be better to post it to the "IDEA PORTAL".

https://community.servicenow.com/community?id=ideas_list&sysparm_module_id=enhancement_requests

If the question is whether is it possible to obtain reference field information using GET, specifying "sysparam_fields" will limit return fields to those specified.

For example, following will query the incident table and return information on the "assigned_to" field.

GET https://<ServiceNow instance>.service-now.com/api/now/table/incident?sysparm_fields=assigned_to&sysparm_limit=1 

Returned value:

{
  "result": [
    {
      "assigned_to": {
        "link": "https://<ServiceNow instance>.service-now.com/api/now/table/sys_user/5137153cc611227c000bbd1bd8cd2007",
        "value": "5137153cc611227c000bbd1bd8cd2007"
      }
    }
  ]
}

Nishanth5
Kilo Explorer

It's more of a question. I wanted to know if in the response, instead of just getting the link and the value, if there is a way to get additional fields from the reference object, but within the same nested json structure where we get the `link` attribute.