Having issue with mandatory fields

DineshD
Tera Contributor

I'm currently working on ServiceNow REST API to create Incidents. For that I need to get the fields that are mandatory, so that I  can make them required. 

 

I have already tried getting data from sys_dictionary table but the mandatory fields are shown "false" in "mandatory" attribute.

 

Can anyone help me out?

9 REPLIES 9

Hello,

 

Yes so why will scripts rest API not work? It is just the same as normal table API you just need to define the fields which you want to update. And using the link I had shared above you can return an error response if mandatory fields are not passed in the API.

 

Thanks.

kamlesh kjmar
Mega Sage
Mega Sage

Hi @DineshD ,

 

Fields are mostly made mandatory using UI policy/Client script, and is at form level only. Fields made madatory by script, that you will not be able to get via API, sys_dictionary will help you with only those fields of the table that are made mandatory at the dictionary level which is not used very often.

 

But similar to sys_dictionary there are other two tables that stores information about fields made mandatory by UI policies/ Data policies, that also can give you fair idea. Below are the tables you can try:

 

Table Name : sys_ui_policy_action

 

kamleshkjmar_0-1667970515532.png

Table name : sys_data_policy_rule

 

kamleshkjmar_1-1667970625557.png

 

I Hope this helps.

 

Please mark this helpful if this helps and mark as correct if this solves your issue.

 

Regards,

Kamlesh

 

Hi @kamlesh kjmar ,

                                  I have tried getting values from both the tables you mentioned above but I am getting duplicate values for same fields(one have "ignore" and other have "true" for "mandatory" attribute) in sys_ui_policy_action table.

Hi @DineshD ,

 

Yes, Mandatory is a choice field which has 3 options true/false/ignore. Please apply a filter and retreive only those, whose mandatory is true.

 

Regards,

Kamlesh

Tony Chatfield1
Kilo Patron

Hi, if the fields are not mandatory at dictionary level, they may be mandatory in UI policy, data policy, client script or in before insert\update BR's. Rather than trying to identify these requirements dynamically I think you would be better just providing a list of fields that need to be populated.
Also, I would not consider an external API directly creating or updating a record to be best practice for any environment and would recommend scripted REST API\import table type solution to ensure that all fields are correctly populated and return a meaning full response if they are not.