UI Policies dynamically change form behavior based on specified conditions. They control field visibility, mandatory status, and read-only state without requiring JavaScript code.
UI Policies are declarative (no-code) and easier to maintain than client scripts. They run automatically when conditions are met, making forms responsive to user input.
| Feature | UI Policy | Client Script |
|---|---|---|
| Coding Required | No (declarative) | Yes (JavaScript) |
| Actions | Visible, Mandatory, Read-only | Any form manipulation |
| Complexity | Simple conditions | Complex logic |
| Performance | Optimized | Depends on code |
| Maintenance | Easier | Requires developer |
Table: incident Conditions: Priority is 1 (Critical) Actions: - assignment_group: Mandatory = true - assigned_to: Mandatory = true - work_notes: Visible = true Reverse if false: Yes Execute on server: No (runs client-side)
Use "Reverse if false" to automatically undo policy actions when conditions no longer match. Keep UI Policies simple - use client scripts for complex logic.
UI Policy Actions define what happens to specific fields when policy conditions are met.
| Action | Description | Example |
|---|---|---|
| Mandatory | Makes field required | Make assignment_group mandatory for P1 incidents |
| Visible | Shows/hides field | Show resolution fields only when state is Resolved |
| Read only | Makes field non-editable | Make number field read-only after creation |
UI Policy: Show Resolution Fields
Table: incident
Conditions: State is Resolved OR State is Closed
UI Policy Actions:
1. Field: close_notes
- Visible: true
- Mandatory: true
2. Field: close_code
- Visible: true
- Mandatory: true
3. Field: resolution_info (section)
- Visible: true
For complex scenarios, you can add JavaScript to UI Policies using the "Run scripts" checkbox.
// Script runs when policy conditions are true
function onConditionTrue() {
// Get priority value
var priority = g_form.getValue('priority');
// Set field properties based on priority
if (priority == '1') {
g_form.setMandatory('assignment_group', true);
g_form.setMandatory('assigned_to', true);
g_form.showFieldMsg('priority', 'Critical - Immediate response required', 'error');
}
}
// Script runs when policy conditions become false
function onConditionFalse() {
g_form.setMandatory('assignment_group', false);
g_form.setMandatory('assigned_to', false);
g_form.hideFieldMsg('priority');
}
Use UI Policy scripts only when standard actions aren't sufficient. For purely visibility/mandatory/readonly changes, use standard UI Policy actions for better performance.
UI Actions are buttons, links, or context menu items that execute custom functionality on forms, lists, or related lists.
| Type | Location | Use Case |
|---|---|---|
| Form Button | Top or bottom of form | Submit, Update, Close incident |
| Form Link | Form header/footer | Open related record, Print |
| Form Context Menu | Right-click menu | Insert and Stay, Delete |
| List Button | Above list | New, Export, Bulk actions |
| List Choice | Actions on selected dropdown | Update selected, Delete selected |
| List Banner Button | List banner area | Create new type records |
// UI Action Configuration:
Name: Escalate to Manager
Table: incident
Action name: escalate_manager
Client: true
Form button: true
Condition: current.state < 6 && current.priority <= 2
// Client Script:
function onClick() {
// Validate
if (g_form.getValue('assignment_group') == '') {
alert('Please assign to a group first');
return false;
}
// Confirm action
var confirmed = confirm('Escalate this incident to management?');
if (!confirmed) {
return false;
}
// Update fields
g_form.setValue('escalation', '1');
g_form.setValue('priority', '1');
g_form.addInfoMessage('Incident escalated to management');
// Submit form
g_form.submit();
}
// UI Action Configuration:
Name: Assign to Me
Table: incident
Action name: assign_to_me
Client: false (server-side)
Form button: true
Condition: current.assigned_to.nil()
// Server Script:
(function() {
// Assign to current user
current.assigned_to = gs.getUserID();
current.state = '2'; // In Progress
current.update();
// Display success message
gs.addInfoMessage('Incident assigned to you');
// Return to form
action.setRedirectURL(current);
})();
Client-side: Faster, validates before submission, can prevent form submit. Server-side: Access to full GlideRecord API, more secure for data changes, can trigger business rules.
Conditions control when UI Actions are visible/available to users.
// Show only for active incidents
current.active == true
// Show for high priority only
current.priority == '1' || current.priority == '2'
// Show only if unassigned
current.assigned_to.nil()
// Show only for specific users/roles
gs.hasRole('itil') || gs.hasRole('admin')
// Show only on new records
current.isNewRecord()
// Show only on existing records
!current.isNewRecord()
// Show based on state
current.state != '6' && current.state != '7'
// Complex condition
current.priority <= '2' && current.assignment_group.nil() && gs.hasRole('manager')
// UI Action Configuration:
Name: Bulk Assign
Table: incident
List choice: true
Client: false
// Server Script:
(function() {
var records = [];
var sysIds = g_list.getChecked().split(',');
// Get assignment group from user
var groupID = g_form.getValue('assignment_group');
if (!groupID) {
gs.addErrorMessage('Please select an assignment group first');
return;
}
// Update all selected records
var gr = new GlideRecord('incident');
for (var i = 0; i < sysIds.length; i++) {
if (gr.get(sysIds[i])) {
gr.assignment_group = groupID;
gr.state = '2'; // In Progress
gr.update();
records.push(gr.number.toString());
}
}
gs.addInfoMessage('Updated ' + records.length + ' incidents: ' + records.join(', '));
})();