Data policies & UI policies
Enforce field rules, on the form and everywhere else.
Both UI policies and data policies control whether fields are mandatory, read-only or visible, but they act in different places, run at different points in a record's lifecycle, and answer to different rules of precedence.
- UI policies
- Data policies
- How the two relate, and converting between them
- Step by step: create a data policy
- Where policies sit among the other rules
Enforce field rules, on the form and everywhere else.
Both UI policies and data policies control whether fields are mandatory, read-only or visible, but they act in different places, run at different points in a record's lifecycle, and answer to different rules of precedence. Choosing the right one (and understanding how it interacts with client scripts, ACLs and dictionary defaults) is one of the everyday judgement calls a ServiceNow admin makes. This lesson goes through both mechanisms in depth.
A UI policy is a client-side rule that reacts as the user fills in a form. A data policy is a server-side rule enforced whenever a record is written, no matter the channel, form, import, API, or script.
UI policies
A UI policy (sys_ui_policy) runs in the browser, on a form, in response to a condition you define. When the condition is true it applies a set of UI Policy Actions to named fields, and optionally runs a script. All of this happens client-side, without you writing a client script by hand, which is exactly why UI policies are preferred over onChange scripts for simple mandatory/read-only/visible behaviour.
Each UI policy has three moving parts:
- Condition, a condition builder expression (e.g.
Priority is 1 - Critical). While a form is open the condition is re-evaluated every time a relevant field changes. - UI Policy Actions, one row per field, each setting Mandatory, Read only and Visible to
True,FalseorLeave alone.Leave alonemeans "don't touch this attribute", critical for letting multiple policies co-operate. - Scripts, optional Execute if true / Execute if false client scripts for logic the actions can't express.
Two checkboxes govern when a UI policy fires:
- Reverse if false, when the condition becomes false again, undo the actions (revert fields to their previous state). Leave this on unless you deliberately want a one-way change.
- On load, evaluate the policy immediately when the form opens, not only after a field changes. Turn this off for policies that should only react to user edits.
Order matters. UI policies have an Order field and run low-to-high; UI policies run after client scripts of the same trigger, and a later policy's True/False action will override an earlier one, which is why Leave alone exists. A UI policy can also be scoped to a view and to Global vs a specific table via Inherits, so a policy on task can cascade to incident, problem and change.
Data policies
A data policy (sys_data_policy2) enforces the same mandatory / read-only rules, but at the data layer. It runs on the server whenever a record on that table is inserted or updated, so it holds regardless of how the record arrived: a form submission, an Import Set load, an inbound REST/SOAP call, or a GlideRecord script. This is the mechanism you use to guarantee data quality across every channel, a form-only rule is trivially bypassed by an import.
Data policies support the same three attributes through Data Policy Rules: Mandatory and Read only per field (there is no "visible" at the data layer, visibility is purely a form concept). A field that a data policy marks read-only cannot be changed by any write, which is a stronger guarantee than a UI policy's read-only field.
Two settings decide the reach of a data policy:
- Apply to imports, enforce the rule during Import Set transforms. Off by default, and one of the most common oversights: a "mandatory" data policy that quietly lets bad import rows through because this box was never ticked.
- Use as UI policy on the client, mirror the data policy onto the form as well, so users get immediate client-side feedback in addition to server enforcement. This gives you one rule that covers both worlds.
Here is exactly why the channel matters. Say Short description is required. A UI policy stops a user submitting the empty form, but a background script writes straight to the table and never sees that policy:
var gr = new GlideRecord('incident'); gr.initialize(); gr.priority = 1; gr.insert(); // no short_description, a UI policy can't stop this
With only a UI policy in place, that insert succeeds and a junk record lands in the table.
Add a data policy that marks Short description mandatory, and the same insert() is rejected server-side, it returns null and logs:
Data Policy Exception: 'Short description' is mandatory
How the two relate, and converting between them
Because they share the same field attributes, ServiceNow lets you convert between the two. From a UI policy you can generate an equivalent data policy (and vice versa) using the related links / conversion action, so a rule that started life on the form can be promoted to data-layer enforcement without rebuilding it. The typical mature pattern is a single data policy with "Use as UI policy on the client" enabled: server-side integrity plus form-side UX from one record.
Step by step: create a data policy
incident) and a Conditions filter, leave it blank to apply to every record.true.Where policies sit among the other rules
Mandatory/read-only can also come from the dictionary (a field marked mandatory in sys_dictionary), from ACLs (write access), and from client scripts using g_form.setMandatory() etc. When several of these disagree, the practical precedence on a form is: dictionary default → UI policy / data-policy-as-UI → client scripts running later can override, but ACLs are the ultimate authority, no policy can make a field editable that the user has no write ACL for. For genuine integrity, put the rule at the data layer; use the form-side layers for guidance and UX, not as your security boundary.
Go deeper
Optional deep-dives, expand the ones you need.
When to reach for each
- Dynamic form behaviour only, show a field when Category is "Hardware", make Assignment group mandatory when State is "Assigned"? UI policy.
- The rule must hold on imports, integrations and background scripts? Data policy with Apply to imports on.
- You want both integrity and instant form feedback? One data policy with Use as UI policy on the client, don't maintain two records that can drift apart.
- The logic is too complex for condition + actions (cross-field maths, async lookups)? Fall back to a client script or business rule, but only then.
Common mistakes
- Relying on a UI policy for data integrity, an Import Set or REST insert sails straight past it because it never touched a form.
- Creating a data policy but forgetting to tick Apply to imports, so the "mandatory" rule silently does nothing during loads.
- Maintaining a separate UI policy and data policy for the same rule; they drift apart. Use one data policy with the client flag instead.
- Setting actions to
True/Falsewhen you meantLeave alone, causing two policies to fight over the same field. - Expecting a policy to override an ACL, it can't grant write access the user doesn't have.
- Reaching for a business rule or client script where a no-code policy would have done the job in half the time.