User Interface Policies and Client Scripts control what happens on a form the moment a user types or clicks, without waiting for the server to respond. They make forms feel responsive and enforce data quality rules instantly, which is why every ServiceNow Certified Application Developer must understand when to use each one.
Jump to a section
A simple way to picture User Interface Policies and Client Scripts
When you check into a hotel, the front desk agent first hands you a registration form on a clipboard. This form is designed using a UI Policy: certain fields, like your phone number, become mandatory only if you check the box for 'I want a wake-up call'. The agent cannot hand you the form without those conditional rules being active. Once you hand the filled form back, the agent immediately reviews it using a Client Script: if you wrote a phone number that is only 5 digits long, a pop-up appears saying 'Please enter a valid 10-digit phone number with area code'. This happens before any data is sent to the hotel's central booking system.
The manager never sees an incorrect form because the front desk agent caught the mistake right there, at the check-in counter. The UI Policy is the printed rulebook on the clipboard that tells the form which fields to show and which to require. The Client Script is the smart agent who double-checks your answers on the spot and asks you to fix them before you walk away. In ServiceNow, this saves the server from wasting time processing bad data and saves the user from waiting for a slow error message later.
In ServiceNow, a form is not just a static page of input boxes. Every time you open a record — like an incident, a change request, or a user profile — a series of instructions run in your web browser that decide what you see and how you can interact with it. These instructions are called UI Policies and Client Scripts, and they run on the client side. 'Client side' means inside your browser, on your own computer, not on ServiceNow's cloud servers. This is important because client-side actions feel instant — there is no round trip waiting for the server to respond.
A UI Policy is a declarative rule. 'Declarative' means you tell ServiceNow what should happen without writing complex programming logic: for example, 'if the Category field is set to Network, then make the Subcategory field mandatory and visible'. The UI Policy consists of one or more conditions (if/then statements) and one or more actions (make field mandatory, make field visible, make field read-only). When a user changes a field on the form, the UI Policy engine re-evaluates those conditions immediately. If the conditions are met, the specified actions are applied. If the conditions are no longer met, the actions are reversed. UI Policies are the easiest way to make a form dynamic without writing any code, and they are the preferred method for simple conditional behaviours.
A Client Script, on the other hand, is actual JavaScript code that you write to perform more complex or custom behaviour that a UI Policy cannot handle. JavaScript is the programming language that runs in web browsers. Client Scripts can do many things: validate that a date range makes sense, auto-populate a field based on the user's location, show a warning message, or calculate a total. There are several types of Client Script, each designed to run at a different moment in the form's lifecycle:
onChange: runs when a specific field's value is changed by the user. You configure the script to watch one field, and the script runs only when that field changes.
onSubmit: runs when the user clicks the Submit or Save button. This is the most common type for validation. If the script returns false, the form does not save, and the user sees an error message.
onLoad: runs once when the form first loads. It is often used to set default values or hide sections based on data that is already on the form.
onCellEdit: runs when a cell is edited in a list view (not a form). This is less common for beginners but appears on the exam.
Why do both technologies exist? UI Policies are simpler and require no coding, making them safer for administrators who are not developers. However, UI Policies are limited: they can only do what the declarative actions allow. They cannot, for example, check if a date is more than 30 days in the past, or concatenate two fields together. Client Scripts do not have those limitations because you can write any custom validation logic in JavaScript. The cost is that Client Scripts require programming skill, and a badly written Client Script can make a form slow or cause errors.
A common real-world example: imagine an IT help desk form for requesting a new laptop. A UI Policy could make the 'Laptop Model' field mandatory only when the request type is 'New Hardware'. That is a simple condition. A Client Script could then check that the user's manager is not the same person as the requester — something a UI Policy cannot evaluate because it involves comparing two field values. The Client Script runs onSubmit and, if the manager is the same as the requester, shows an error message and prevents the save.
The order of execution matters. When a form loads, onLoad Client Scripts run first, then UI Policies are evaluated. When a field changes, the onChange Client Script runs, then UI Policies are re-evaluated. When the user clicks Save, the onSubmit Client Script runs first, and only if it returns true (meaning all validations passed) does the form submit to the server. This order is critical because if an onLoad script hides a field, a UI Policy might try to make it mandatory, causing confusion. Developers must think about the sequence to avoid conflicts.
For the SNOW-CAD exam, you need to know which tool to use for a given requirement. Use a UI Policy when the requirement is simple, condition-based, and involves only making fields mandatory, visible, or read-only. Use a Client Script when you need custom logic, complex calculations, or validation that compares multiple fields together. The exam will present scenarios and ask you to choose the correct implementation.
Identify the requirement
Read the business requirement carefully. Does it involve only making a field mandatory, visible, or read-only based on a condition? If yes, plan to use a UI Policy. Does it involve calculating a value, comparing two fields, showing a custom error message, or setting a field's value? If yes, plan to use a Client Script. This first step determines which tool you will use.
Define the condition
In the UI Policy record, set the condition (for example, 'Category is Network'). You can use 'And/Or' conditions for multiple criteria. The condition is evaluated on the client side. If the condition is true, the actions you specify will apply. If the condition is false, any actions that were applied will be reversed.
Add UI Policy actions
Add one or more actions from the dropdown: mandatory (true/false), visible (true/false), or read-only (true/false). Each action applies to a specific field on the form. For example, you can set 'Subcategory' mandatory when 'Category is Hardware'. You can add multiple actions for different fields in the same policy.
Create the Client Script (if applicable)
Navigate to System Definition > Client Scripts and click New. Choose the correct type: onLoad for scripts that run when the form opens, onChange for scripts that run when a specific field changes, or onSubmit for scripts that run when the user clicks Save. Give the script a meaningful name.
Write the JavaScript code
In the 'Script' field, write JavaScript code using the g_form API. For example, to validate that a description is long enough, use: if (g_form.getValue('short_description').length < 10) { g_form.addErrorMessage('Description too short'); return false; }. For an onChange script, use the 'control' parameter to check the changed field. Always test your script in a sandbox before deploying to production.
Test the behaviour thoroughly
Open a new record or an existing one and verify that the UI Policy applies and reverses correctly as you change relevant fields. For Client Scripts, trigger the event (e.g., change the watched field, or click Save) and confirm the expected behaviour — field updates, error messages, or blocked saves. Check for unintended side effects, such as a script that accidentally hides a field that should remain visible.
Imagine you work as a ServiceNow administrator for a mid-sized company that uses the platform to manage IT support requests. The service desk team receives dozens of incident tickets every day, and they need a way to ensure that each ticket contains all the necessary information before it gets assigned to a technician. Currently, agents spend too much time calling users back to ask for missing details, which delays resolution times. Your manager asks you to improve the incident form so that the required information is enforced at the point of entry — when the user submits the ticket through the self-service portal.
You start by identifying the fields that are commonly left blank: the 'Category' field, the 'Short Description', and the 'Contact Type' (phone, email, walk-in). Your first step is to create a UI Policy on the incident form. You set the condition to 'Always' — meaning this policy applies to every new incident. You then configure three actions: set 'Category' to mandatory, set 'Short Description' to mandatory, and set 'Contact Type' to mandatory. That is it. No code needed. The next time a user tries to submit a ticket with an empty Category, the form will highlight the field in red and prevent submission. This solves the most basic problem.
But you notice a more subtle issue. When a user selects 'Email' as the Contact Type, agents expect an email address to be filled in, not a phone number. A UI Policy can handle this too: you add a condition that says 'Contact Type is Email'. Under that condition, you set the 'Email Address' field to mandatory and the 'Phone Number' field to hidden. When the user switches Contact Type to 'Phone', the opposite happens. This is a perfect use for UI Policy because it is a simple if-then rule about visibility and requirement.
Now, your manager reports another problem: users sometimes enter a 'Short Description' that is shorter than 10 characters, which is not useful for diagnosing the issue. A UI Policy cannot check character count — it can only make a field mandatory or visible. You need a Client Script for this. You create an onSubmit Client Script on the incident form. The script runs JavaScript code that reads the length of the 'Short Description' field. If the length is less than 10, the script displays an error message saying 'Please provide a more detailed description (at least 10 characters)' and returns false, which cancels the save. The user stays on the form and can fix the problem.
Later, you want to automatically set the 'Assignment Group' based on the selected Category. For example, if the Category is 'Network', the script should set the Assignment Group to 'Network Team'. This cannot be done with a UI Policy alone because setting a field's value is not an action available in UI Policies. You write an onChange Client Script on the 'Category' field. When the Category changes, the script checks the new value and uses a simple if-else to set the 'Assignment Group' field automatically. This saves the user from having to search for the correct group in a long list.
Over the next few weeks, you continue to refine the form. You add an onLoad Client Script that hides the 'Resolution Notes' field when the incident is new (state is 'New'), because that field should only be filled by the technician once work begins. You also add a UI Policy that makes the 'Resolution Code' field mandatory when the state changes to 'Resolved'. The combination of UI Policies for simple rules and Client Scripts for complex logic keeps the form clean, responsive, and reliable. Your service desk team reports a 40% reduction in incomplete tickets, and your manager is impressed with the improvement.
The SNOW-CAD exam tests your ability to choose between UI Policies and Client Scripts for given scenarios. The exam writers love to present a requirement and ask which tool you would use, or whether a specific behaviour requires a UI Policy, a Client Script, or both. They also test the exact order of execution, the types of Client Scripts, and the limitations of each tool.
Here are the specific exam topics you must master:
Recognising when to use a UI Policy versus a Client Script. The exam will give you a description of a form behaviour, such as 'make field X mandatory when field Y is empty'. If the requirement is only about making a field mandatory, visible, or read-only based on a condition, the answer is UI Policy. If the requirement involves calculations, string manipulation, setting field values, or comparing data across multiple fields, the answer is Client Script.
Identifying the correct Client Script type. You will be asked: 'A requirement states that a script should run when the user clicks Submit. Which client script type should you use?' The answer is onSubmit. Similarly, 'A script should run when the value of the Category field changes' — the answer is onChange.
Understanding the order of execution. A common trap question describes a scenario where both an onLoad Client Script and a UI Policy affect the same field, and asks what happens. The correct answer is that the onLoad script runs first, followed by the UI Policy. If the UI Policy contradicts the script, the UI Policy's actions (mandatory, visible, read-only) will override any visual changes made by the script that was not specifically about those properties.
Knowing the limitations of UI Policies. The exam will list several possible actions — show a warning message, make a field mandatory, set a field value, run a calculation — and ask which ones a UI Policy can perform. The correct answer is that UI Policies can only make fields mandatory, visible (shown/hidden or read-only), and nothing else. If the requirement includes setting a field's value or showing a pop-up, it must be a Client Script.
The 'GlideForm' (g_form) API. The exam will ask about methods like g_form.getValue(), g_form.setValue(), g_form.setMandatory(), g_form.setDisplay(), and g_form.addErrorMessage(). You need to know which methods are used in Client Scripts. For example, g_form.setMandatory('field_name', true) makes a field mandatory from within a Client Script, even though a UI Policy can also do it. The exam team likes to test the distinction between the declarative approach (UI Policy) and the programmatic approach (Client Script using g_form).
The 'true' and 'false' return values for onSubmit. The exam will present a Client Script that returns false under certain conditions. You must understand that returning false prevents the form from saving. Returning true (or nothing) allows the save. They may ask you to identify a script that incorrectly allows saving when it should not.
Read-only versus disabled. UI Policies can set a field to 'read-only', meaning the user can see the value but cannot edit it. The exam will not ask about 'disabled' in this context — focus on read-only.
The scope of execution. Client Scripts run on the client (browser). They cannot access server-side data directly unless they use GlideRecord or GlideAjax, which are more advanced topics. The exam expects you to know that Client Scripts are for client-only actions, and any server-side logic must be handled by Business Rules or Scripted REST APIs.
Common traps the exam sets:
Presenting a requirement that can be solved by both a UI Policy and a Client Script, and asking which is 'the best choice'. The correct answer is always UI Policy because it is simpler, faster, and less error-prone.
Giving a scenario where the condition for a UI Policy uses a field that does not exist on the form. UI Policies are evaluated only against fields present in the current form layout, so a condition referencing a missing field will never be true.
Confusing 'onChange' with 'onSubmit'. An onChange script triggers on every field change, not just on save. The exam may ask about performance: if you need to run validation only at save time, use onSubmit, not onChange, because onChange runs every time the field changes, which can slow down the form.
Asking about the 'Default Value' behaviour. UI Policies do not set default values; that is done via Default Values (a separate configuration) or an onLoad Client Script.
UI Policies are declarative rules that can only make fields mandatory, visible, hidden, or read-only — they cannot set field values or show pop-up messages.
Client Scripts are custom JavaScript code that run in the browser and can perform any action, including validation, calculations, and setting field values.
Use a UI Policy when the requirement is a simple condition about a field's appearance or requirement; use a Client Script when you need logic, comparisons, or custom feedback.
The order of execution is onLoad Client Script first, then UI Policy on load; onChange Client Script first, then UI Policy on field change; onSubmit Client Script runs before the save is final.
An onSubmit Client Script that returns false prevents the form from saving — the user cannot bypass it by clicking Save again.
UI Policies are evaluated against fields present in the current form layout; if a field in the condition is not on the form, the policy condition evaluates to false.
The g_form API is used inside Client Scripts to read values (getValue), set values (setValue), and control field properties (setMandatory, setDisplay).
For SNOW-CAD exam questions, always prefer UI Policy over Client Script if the requirement falls within UI Policy capabilities — it is simpler and less error-prone.
These come up on the exam all the time. Here's how to tell them apart.
UI Policy
Declarative rules — no programming required
Can only make fields mandatory, visible, or read-only
Evaluated after Client Scripts on each event (load, change)
Client Script
Custom JavaScript code required
Can perform any action: validation, calculation, setting field values, showing messages
Runs before UI Policy on each event for the same form
onSubmit Client Script
Runs when the user clicks Save or Submit
Can return false to block the save entirely
Used for final validation before data is sent to server
onChange Client Script
Runs when a specific field's value is changed
Cannot control the save operation — only reacts to field changes
Used for auto-population or real-time feedback as user types
UI Policy (client-side)
Runs in the browser, instant feedback
Controls only mandatory, visible, read-only properties
Cannot access server-side records or perform database operations
Business Rule (server-side)
Runs on the server after a record is saved
Can update any field in the database, run calculations, or trigger email notifications
Cannot control the form appearance or stop the save from the client side
g_form.getValue()
Used to read the current value of a field from the browser
Returns a string (text) of the field's value
Can be used inside any Client Script type
g_form.setValue()
Used to change the value of a field displayed to the user
Does not save to the database until the form is submitted
Typically used in onChange or onLoad scripts to auto-populate fields
Mistake
UI Policies and Client Scripts are interchangeable — you can always use one instead of the other.
Correct
UI Policies can only make fields mandatory, visible/hidden, or read-only. Any behaviour beyond that — setting a field value, showing a pop-up, validating data — requires a Client Script.
Newcomers see both being used to control forms and assume they are two ways to achieve the same thing, when in fact they have different capabilities and purposes.
Mistake
Once a UI Policy makes a field mandatory, a Client Script can never remove that mandatory setting.
Correct
A Client Script can override the mandatory setting using g_form.setMandatory('field', false) at any time — even after a UI Policy has set it.
Beginners think UI Policies are final because they are 'policies', but in execution order, a Client Script runs before the UI Policy on load, and can change properties afterwards if the script runs again later.
Mistake
onSubmit Client Scripts can prevent a record from being saved by showing a warning message that the user can ignore.
Correct
An onSubmit Client Script that returns false (or calls g_form.addErrorMessage() and then returns false) completely blocks the save. The user cannot ignore it — they must fix the issue or the record stays unsaved.
People confuse 'warning' (a message that does not stop the save) with 'validation error' (which stops the save). The exam tests the difference.
Mistake
UI Policies can set a field's value to a specific number or text automatically.
Correct
UI Policies cannot set or change field values. They only control whether a field is mandatory, visible, or read-only. Setting a value requires a Client Script or a Default Value configuration.
The word 'policy' sounds powerful, and beginners assume it can do everything, but its actions are limited by design.
Mistake
A UI Policy runs after a Client Script on field change, so the UI Policy wins in any conflict.
Correct
On field change, the onChange Client Script runs first, followed by the UI Policy evaluation. The UI Policy's actions (mandatory, visible, read-only) are applied after the script, so they can override the script's changes to those specific properties.
Beginners misunderstand the order and assume the script always wins because it is code, but UI Policies are designed to be the final authority on mandatory/visible/read-only states.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
Yes. A UI Policy has a condition that determines when it is active. When the condition is true, the mandatory action is applied. When the condition is false, the field returns to its default state (not mandatory).
If the requirement is only about making fields mandatory, visible/hidden, or read-only based on a condition, use a UI Policy. If it involves calculations, setting field values, showing custom messages, or comparing multiple fields, use a Client Script.
Yes, an onLoad Client Script runs automatically when the form is opened, before the user interacts with any field. It is often used to set default values or hide sections based on existing data.
The order of execution determines the outcome. On form load, the onLoad Client Script runs first, then the UI Policy. On field change, the onChange Client Script runs first, then the UI Policy. The UI Policy's mandatory/visible/read-only actions are applied after the script, so the UI Policy wins for those specific properties.
Yes. Use an onSubmit Client Script. If the script returns false, the form will not save and the user stays on the form. You can also call g_form.addErrorMessage() to show a friendly error message before returning false.
No. UI Policies cannot set field values. To set a default value, use the 'Default Value' configuration on the dictionary entry of the field, or use an onLoad Client Script with g_form.setValue().
You've finished User Interface Policies and Client Scripts. Continue through the SNOW-CAD study guide to build a complete picture of the exam.
Done with this chapter?