|
| 1 | +# Field Character Counter |
| 2 | + |
| 3 | +## Use Case |
| 4 | +Provides real-time character count feedback for text fields in ServiceNow forms. Shows remaining characters with visual indicators to help users stay within field limits. |
| 5 | + |
| 6 | +## Requirements |
| 7 | +- ServiceNow instance |
| 8 | +- Client Script execution rights |
| 9 | +- Text fields with character limits |
| 10 | + |
| 11 | +## Implementation |
| 12 | +1. Create a new Client Script with Type "onChange" |
| 13 | +2. Copy the script code from `script.js` |
| 14 | +3. Configure the field name and character limit in the script |
| 15 | +4. Apply to desired table/form |
| 16 | +5. Save and test |
| 17 | + |
| 18 | +## Configuration |
| 19 | +Edit these variables in the script: |
| 20 | + |
| 21 | +```javascript |
| 22 | +var fieldName = 'short_description'; // Your field name |
| 23 | +var maxLength = 160; // Your character limit |
| 24 | +``` |
| 25 | + |
| 26 | +## Features |
| 27 | +- Real-time character counting as user types |
| 28 | +- Visual indicators: info (blue), warning (yellow), error (red) |
| 29 | +- Shows "X characters remaining" or "Exceeds limit by X characters" |
| 30 | +- Automatically clears previous messages |
| 31 | + |
| 32 | +## Common Examples |
| 33 | +```javascript |
| 34 | +// Short Description (160 chars) |
| 35 | +var fieldName = 'short_description'; |
| 36 | +var maxLength = 160; |
| 37 | + |
| 38 | +// Description (4000 chars) |
| 39 | +var fieldName = 'description'; |
| 40 | +var maxLength = 4000; |
| 41 | + |
| 42 | +// Work Notes (4000 chars) |
| 43 | +var fieldName = 'work_notes'; |
| 44 | +var maxLength = 4000; |
| 45 | +``` |
| 46 | + |
| 47 | +## Message Thresholds |
| 48 | +- **50+ remaining**: Info message (blue) |
| 49 | +- **1-20 remaining**: Warning message (yellow) |
| 50 | +- **Over limit**: Error message (red) |
| 51 | + |
| 52 | +## Notes |
| 53 | +- Uses standard ServiceNow APIs: `g_form.showFieldMsg()` and `g_form.hideFieldMsg()` |
| 54 | +- Create separate Client Scripts for multiple fields |
| 55 | +- Works with all text fields and text areas |
| 56 | +- Character count includes all characters (spaces, punctuation, etc.) |
0 commit comments