|
| 1 | +# Form Field Dependencies Manager |
| 2 | + |
| 3 | +A powerful utility for managing complex field relationships and dependencies in ServiceNow Catalog Items. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Dynamic field relationships |
| 8 | +- Cascading field updates |
| 9 | +- Conditional visibility rules |
| 10 | +- Dynamic mandatory field rules |
| 11 | +- Value mapping between fields |
| 12 | +- Dependency chain tracking |
| 13 | +- Error handling and logging |
| 14 | + |
| 15 | +## Types of Dependencies |
| 16 | + |
| 17 | +1. **Cascading Changes** |
| 18 | + - Update dependent fields automatically |
| 19 | + - Complex value calculations |
| 20 | + - Multi-field dependencies |
| 21 | + |
| 22 | +2. **Visibility Rules** |
| 23 | + - Show/hide fields based on conditions |
| 24 | + - Multiple condition support |
| 25 | + - Complex visibility logic |
| 26 | + |
| 27 | +3. **Mandatory Rules** |
| 28 | + - Dynamic required field handling |
| 29 | + - Condition-based mandatory flags |
| 30 | + - Multiple rule support |
| 31 | + |
| 32 | +4. **Value Mappings** |
| 33 | + - Automatic value population |
| 34 | + - Complex value transformations |
| 35 | + - Multi-field mapping support |
| 36 | + |
| 37 | +## Implementation |
| 38 | + |
| 39 | +### Basic Setup |
| 40 | + |
| 41 | +1. Create a new Catalog Client Script: |
| 42 | + ```javascript |
| 43 | + Table: Catalog Client Script [catalog_script_client] |
| 44 | + Type: Both onLoad and onChange |
| 45 | + Active: true |
| 46 | + ``` |
| 47 | + |
| 48 | +2. Copy the content of `script.js` into your script |
| 49 | + |
| 50 | +### Configuration Examples |
| 51 | + |
| 52 | +1. **Cascading Update** |
| 53 | +```javascript |
| 54 | +var manager = new FieldDependenciesManager(); |
| 55 | +manager.addDependency({ |
| 56 | + type: 'cascade', |
| 57 | + sourceField: 'department', |
| 58 | + targetField: 'assignment_group', |
| 59 | + rule: function(value, cache) { |
| 60 | + // Return assignment group based on department |
| 61 | + return departmentToGroupMapping[value] || ''; |
| 62 | + } |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | +2. **Visibility Rule** |
| 67 | +```javascript |
| 68 | +manager.addDependency({ |
| 69 | + type: 'visibility', |
| 70 | + sourceField: 'category', |
| 71 | + targetField: 'subcategory', |
| 72 | + rule: function(value, cache) { |
| 73 | + return value === 'hardware' || value === 'software'; |
| 74 | + } |
| 75 | +}); |
| 76 | +``` |
| 77 | + |
| 78 | +3. **Mandatory Field Rule** |
| 79 | +```javascript |
| 80 | +manager.addDependency({ |
| 81 | + type: 'mandatory', |
| 82 | + sourceField: 'impact', |
| 83 | + targetField: 'priority', |
| 84 | + rule: function(value, cache) { |
| 85 | + return value === 'high'; |
| 86 | + } |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +4. **Value Mapping** |
| 91 | +```javascript |
| 92 | +manager.addDependency({ |
| 93 | + type: 'valueMap', |
| 94 | + sourceField: 'country', |
| 95 | + targetField: 'currency', |
| 96 | + rule: function(value, cache) { |
| 97 | + return countryCurrencyMap[value] || 'USD'; |
| 98 | + } |
| 99 | +}); |
| 100 | +``` |
| 101 | + |
| 102 | +## Technical Details |
| 103 | + |
| 104 | +### Dependencies |
| 105 | +- ServiceNow Platform UI Framework |
| 106 | +- GlideForm API |
| 107 | + |
| 108 | +### Performance Considerations |
| 109 | +- Efficient caching mechanism |
| 110 | +- Optimized dependency processing |
| 111 | +- Circular dependency prevention |
| 112 | + |
| 113 | +### Browser Support |
| 114 | +- Works with all modern browsers |
| 115 | +- ES5+ compatible |
| 116 | + |
| 117 | +## Best Practices |
| 118 | + |
| 119 | +1. **Performance** |
| 120 | + - Group related dependencies |
| 121 | + - Use efficient rules |
| 122 | + - Avoid complex calculations |
| 123 | + |
| 124 | +2. **Maintenance** |
| 125 | + - Document dependencies |
| 126 | + - Use meaningful rule names |
| 127 | + - Keep rules simple |
| 128 | + |
| 129 | +3. **User Experience** |
| 130 | + - Clear field relationships |
| 131 | + - Immediate feedback |
| 132 | + - Logical dependencies |
| 133 | + |
| 134 | +## Troubleshooting |
| 135 | + |
| 136 | +Common issues and solutions: |
| 137 | + |
| 138 | +1. **Dependencies not triggering** |
| 139 | + - Check rule configuration |
| 140 | + - Verify field names |
| 141 | + - Check console for errors |
| 142 | + |
| 143 | +2. **Circular Dependencies** |
| 144 | + - Review dependency chain |
| 145 | + - Check log output |
| 146 | + - Simplify relationships |
| 147 | + |
| 148 | +3. **Performance Issues** |
| 149 | + - Optimize rule calculations |
| 150 | + - Reduce dependency complexity |
| 151 | + - Check browser console |
| 152 | + |
| 153 | +## Example Use Cases |
| 154 | + |
| 155 | +1. **IT Request Form** |
| 156 | +```javascript |
| 157 | +// Hardware request dependencies |
| 158 | +manager.addDependency({ |
| 159 | + type: 'cascade', |
| 160 | + sourceField: 'hardware_type', |
| 161 | + targetField: 'model', |
| 162 | + rule: function(value, cache) { |
| 163 | + return getModelsForHardwareType(value); |
| 164 | + } |
| 165 | +}); |
| 166 | +``` |
| 167 | + |
| 168 | +2. **HR Service Catalog** |
| 169 | +```javascript |
| 170 | +// Leave request dependencies |
| 171 | +manager.addDependency({ |
| 172 | + type: 'mandatory', |
| 173 | + sourceField: 'leave_type', |
| 174 | + targetField: 'return_date', |
| 175 | + rule: function(value, cache) { |
| 176 | + return value === 'extended_leave'; |
| 177 | + } |
| 178 | +}); |
| 179 | +``` |
| 180 | + |
| 181 | +## Version Information |
| 182 | + |
| 183 | +- Compatible with ServiceNow: Rome and later |
| 184 | +- Last Updated: October 2025 |
0 commit comments