REST API for UI Policy and Data Policy

lexicalunit
Giga Expert

I have tried to search the documentation for an API that allows me to fetch information on the current UI Policy or for Data Policies and I can't find it. Is there such an API?

 

Particularly, I am interested in learning about mandatory fields for incidents. I understand that you can set fields as mandatory in the UI Policy and in Data Policies.

 

As such, I need a REST API that will allow me to query the current UI Policy and Data Policies to build a full picture of the list of mandatory fields.

 

I'm sure these REST APIs and/or GraphQL APIs must exist. Right?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@lexicalunit 

I don't think any such API exists

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

View solution in original post

5 REPLIES 5

jcmings
Mega Sage

Maybe I am misunderstanding, but I don't think you would need or even want a REST API to achieve this. There are a number of places you can look:

 

  • On the UI Policy Actions table (this is where UI Policies can set mandatory values with a low-code approach)
  • In the Execute if true/Execute if false script fields on the UI Policy records 
  • In the Data Policy Rules (the low-code config for Data Policies)
  • In the script section of client scripts

 

I would start by looking on the UI Policy Actions and Data Policy Rules tables and also doing a search for setMandatory in Studio Code Search.

I am automating the creation of incidents on behalf of a user via an OAuth generated access token. Literally the only method I have of interacting with ServiceNow is via an API. If I can't do it via an API, then I can't do it, period.

MackI
Kilo Sage

hi @lexicalunit 

 

Table API (for Basic Information):

You can use the Table API to query the following tables:

sys_ui_policy: UI Policy records
sys_data_policy: Data Policy records
sys_ui_policy_action: UI Policy Actions (defines actions like making a field mandatory)
sys_data_policy_rule: Data Policy Rules (defines actions like making a field mandatory)

  • Limitations:
    This will only give you the raw data of the policies and their actions.
    You'll need to parse the conditions (which can be scripted) yourself to understand when a field becomes mandatory. This can be quite complex and error-prone.
 
Use Table API, to get all the raw data related to UI policies, data policies, UI actions, and data policy rules.
Parse these tables' data and extract the fields that are mandatory.
Example (to get UI Policies related to the Incident table):
GET /api/now/table/sys_ui_policy?sysparm_query=table=incident
GET /api/now/table/sys_data_policy?sysparm_query=table=incident
GET /api/now/table/sys_ui_policy_action?sysparm_query=ui_policy.table=incident
GET /api/now/table/sys_data_policy_rule?sysparm_query=policy.table=incident
 
Create custom Rest API or use the existing one to get these tables' data in a single call and then write the logic to parse these.
 
Some usage: Security teams can use the Table API to identify UI Policies that might introduce vulnerabilities. I don't know what's your scenario!
 
If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community
 
 
MackI | ServiceNow Developer | 2 *Mainline Certification | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia

hi @lexicalunit 

 

I hope you are well.

 

A small request from my end, If you think my past opinion has some contribution to clear your concept or idea or problem that you faced earlier and resolved it after reviewing and applying it. Please kindly mark this your best answer‌ (Accepted Solution) 🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community.

Now you can accept multiple solutions against your post.

 

Stay safe and well.Thanks

MackI | ServiceNow Developer | 2 *Mainline Certification | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia