GET Mandatory Fields from REST API

lexicalunit
Giga Expert

I need a way to get the list of mandatory fields for an incident so that I can create an incident on behalf of a user. The user will NOT be a System Administrator in this case so the user will not have access to sys_dictionary and can therefore NOT be expected to be able to make a query like the following:

 

curl -XGET "https://${INSTANCE}/api/now/table/sys_dictionary?sysparm_query=name%3Dincident&sysparm_fields=column_label%2Cmandatory%2Cinternal_type" \
    -H "Authorization: Bearer $ACCESS_TOKEN" \
    -H "Accept: application/json"

 

For System Administrators this query will return data which enumerates all the fields for an incident and true/false if they are mandatory.

 

What other way is there within the ServiceNow suite of REST APIs (or any other kind of APIs available to a typical user level client_credentials) that can be used to fetch down the list of fields and if any of them are mandatory or not?

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@lexicalunit 

fields can be mandatory at dictionary level and also at UI level

It's not a good idea to expose sys_dictionary via table API to get these details.

There is no direct API which will give you list of mandatory fields on table.

What if new field is added later as mandatory?

Error of missing mandatory fields in REST 

If this is for integration you should define the mandatory fields within instance and let 3rd party consume a scripted rest api and if any input is missing you can throw the error to 3rd party system.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I plan to fetch down the latest set of mandatory fields before creating an incident via the API. So if new fields are added that is no problem.

@lexicalunit 

so you can check the approach I shared above.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Feels like a bit of a hack to try and create an incident just to see if it fails and if the failure indicates there are mandatory fields. I'll avoid that approach. What happens if the incident creation doesn't fail? Then we're left with some random incident being added to ServiceNow that then has to be cleaned up (deleted).

lexicalunit
Giga Expert

This is not possible to do. You have to create a user with sys_dictionary and sys_dictionary.* access, unfortunately.