|
| 1 | +# Mandatory Field Highlighter |
| 2 | + |
| 3 | +## Use Case |
| 4 | +Provides visual feedback for empty mandatory fields on ServiceNow forms by showing error messages when the form loads. Helps users quickly identify which required fields need to be completed. |
| 5 | + |
| 6 | +## Requirements |
| 7 | +- ServiceNow instance |
| 8 | +- Client Script execution rights |
| 9 | +- Forms with mandatory fields |
| 10 | + |
| 11 | +## Implementation |
| 12 | +1. Create a new Client Script with Type "onLoad" |
| 13 | +2. Copy the script code from script.js |
| 14 | +3. **Customize the fieldsToCheck string** with your form's mandatory field names |
| 15 | +4. Apply to desired table/form |
| 16 | +5. Save and test on a form with mandatory fields |
| 17 | + |
| 18 | +## Configuration |
| 19 | +Edit the `fieldsToCheck` variable to include your form's mandatory fields as a comma-separated string: |
| 20 | + |
| 21 | +```javascript |
| 22 | +// Example configurations for different forms: |
| 23 | + |
| 24 | +// For Incident forms: |
| 25 | +var fieldsToCheck = 'short_description,priority,category,caller_id,assignment_group'; |
| 26 | + |
| 27 | +// For Request forms: |
| 28 | +var fieldsToCheck = 'short_description,requested_for,category,priority'; |
| 29 | + |
| 30 | +// For Change Request forms: |
| 31 | +var fieldsToCheck = 'short_description,category,priority,assignment_group,start_date,end_date'; |
| 32 | + |
| 33 | +// For Problem forms: |
| 34 | +var fieldsToCheck = 'short_description,category,priority,assignment_group'; |
| 35 | + |
| 36 | +// Custom fields (add as needed): |
| 37 | +var fieldsToCheck = 'short_description,priority,u_business_justification,u_cost_center'; |
| 38 | +``` |
| 39 | + |
| 40 | +## Features |
| 41 | +- Shows error messages under empty mandatory fields on form load |
| 42 | +- Easy configuration with comma-separated field names |
| 43 | +- Automatically skips fields that don't exist on the form |
| 44 | +- Only processes fields that are actually mandatory and visible |
| 45 | +- Uses proper ServiceNow client scripting APIs |
| 46 | +- No DOM manipulation or unsupported methods |
| 47 | + |
| 48 | +## Common Field Names |
| 49 | +- `short_description` - Short Description |
| 50 | +- `priority` - Priority |
| 51 | +- `category` - Category |
| 52 | +- `caller_id` - Caller |
| 53 | +- `requested_for` - Requested For |
| 54 | +- `assignment_group` - Assignment Group |
| 55 | +- `assigned_to` - Assigned To |
| 56 | +- `state` - State |
| 57 | +- `urgency` - Urgency |
| 58 | +- `impact` - Impact |
| 59 | +- `start_date` - Start Date |
| 60 | +- `end_date` - End Date |
| 61 | +- `due_date` - Due Date |
| 62 | +- `location` - Location |
| 63 | +- `company` - Company |
| 64 | +- `department` - Department |
| 65 | + |
| 66 | +## Notes |
| 67 | +- Uses g_form.showFieldMsg() method to display error messages |
| 68 | +- Uses g_form.hasField() to safely check field existence (built into the safety checks) |
| 69 | +- Only runs on form load - provides initial validation feedback |
| 70 | +- Easy to customize for different forms by modifying the field list |
| 71 | +- Compatible with all standard ServiceNow forms |
| 72 | +- Lightweight and focused on essential functionality |
| 73 | + |
| 74 | +## Example Usage |
| 75 | +For a typical incident form, simply change the configuration line to: |
| 76 | +```javascript |
| 77 | +var fieldsToCheck = 'short_description,priority,category,caller_id,assignment_group'; |
| 78 | +``` |
| 79 | +Save the Client Script and test on an incident form to see error messages appear under empty mandatory fields. |
0 commit comments