|
1 | 1 | # Mandatory Field Highlighter |
2 | 2 |
|
3 | | -## Use Case / Requirement |
4 | | -Highlight mandatory fields that are empty by showing error messages, making it easier for users to identify which required fields need to be completed. |
| 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 | 5 |
|
6 | | -## Solution |
7 | | -Two client scripts that work together: |
8 | | -1. **onLoad script**: Shows error messages for empty mandatory fields when form loads |
9 | | -2. **onChange script**: Updates error messages in real-time as users fill fields |
10 | | -3. Uses proper ServiceNow methods instead of DOM manipulation |
| 6 | +## Requirements |
| 7 | +- ServiceNow instance |
| 8 | +- Client Script execution rights |
| 9 | +- Forms with mandatory fields |
11 | 10 |
|
12 | 11 | ## Implementation |
13 | | -1. **Create onLoad script**: |
14 | | - - New Client Script, Type: onLoad |
15 | | - - Copy code from `script.js` |
16 | | - - Apply to desired table |
| 12 | +1. Create a new Client Script with Type "onLoad" |
| 13 | +2. Copy the script code from script.js |
| 14 | +3. Apply to desired table/form |
| 15 | +4. Save and test on a form with mandatory fields |
17 | 16 |
|
18 | | -2. **Create onChange script(s)**: |
19 | | - - New Client Script, Type: onChange |
20 | | - - Copy code from `onChange.js` |
21 | | - - **Important**: Replace `'FIELD_NAME'` with actual field name (e.g., 'priority') |
22 | | - - Create separate onChange scripts for each mandatory field you want to validate |
23 | | - - Set the "Field name" in the client script form to the specific field |
24 | | - |
25 | | -## Files |
26 | | -- `script.js`: onLoad client script for initial highlighting |
27 | | -- `onChange.js`: onChange template script for real-time updates |
28 | | - |
29 | | -## Example Usage |
30 | | -For priority field onChange script: |
31 | | -```javascript |
32 | | -var fieldName = 'priority'; // Replace FIELD_NAME with 'priority' |
33 | | -``` |
34 | | - |
35 | | -For category field onChange script: |
36 | | -```javascript |
37 | | -var fieldName = 'category'; // Replace FIELD_NAME with 'category' |
38 | | -``` |
| 17 | +## Features |
| 18 | +- Shows error messages under empty mandatory fields on form load |
| 19 | +- Uses proper ServiceNow client scripting APIs |
| 20 | +- No DOM manipulation or unsupported methods |
| 21 | +- Lightweight and focused functionality |
39 | 22 |
|
40 | 23 | ## Notes |
41 | | -- Uses `g_form.showFieldMsg()` and `g_form.hideFieldMsg()` methods |
42 | | -- Follows ServiceNow best practices (no DOM manipulation) |
43 | | -- Works with standard ServiceNow forms |
44 | | -- Create one onChange script per mandatory field for best results |
| 24 | +- Uses g_form.showFieldMsg() method to display error messages |
| 25 | +- Only runs on form load - no real-time updates |
| 26 | +- Works with all mandatory fields automatically |
| 27 | +- Simple single-script solution |
0 commit comments