|
| 1 | +function onChange(control, oldValue, newValue, isLoading, isTemplate) { |
| 2 | + if (isLoading || newValue === '') { |
| 3 | + return; |
| 4 | + } |
| 5 | + |
| 6 | + // Example: Dynamic behavior when Category changes |
| 7 | + var category = g_form.getValue('category'); |
| 8 | + var impact = g_form.getValue('impact'); |
| 9 | + var urgency = g_form.getValue('urgency'); |
| 10 | + |
| 11 | + // Hide or show certain fields dynamically |
| 12 | + if (category === 'hardware') { |
| 13 | + g_form.setVisible('u_serial_number', true); |
| 14 | + g_form.setMandatory('u_serial_number', true); |
| 15 | + } else { |
| 16 | + g_form.setVisible('u_serial_number', false); |
| 17 | + g_form.setMandatory('u_serial_number', false); |
| 18 | + } |
| 19 | + |
| 20 | + // Auto-calculate Priority based on Impact & Urgency |
| 21 | + // (Client-only logic — no Script Include needed) |
| 22 | + var priorityMap = { |
| 23 | + '1_1': '1', |
| 24 | + '1_2': '2', |
| 25 | + '1_3': '3', |
| 26 | + '2_1': '2', |
| 27 | + '2_2': '3', |
| 28 | + '2_3': '4', |
| 29 | + '3_1': '3', |
| 30 | + '3_2': '4', |
| 31 | + '3_3': '5' |
| 32 | + }; |
| 33 | + |
| 34 | + var key = impact + '_' + urgency; |
| 35 | + var newPriority = priorityMap[key] || '5'; |
| 36 | + g_form.setValue('priority', newPriority); |
| 37 | + |
| 38 | + // how a dynamic message when conditions are met |
| 39 | + if (category === 'hardware' && urgency === '1') { |
| 40 | + g_form.showFieldMsg('category', 'Critical hardware issue detected! Escalate immediately.', 'error'); |
| 41 | + } else { |
| 42 | + g_form.hideFieldMsg('category'); |
| 43 | + } |
| 44 | + |
| 45 | + // Prevent invalid data combination (client-side validation) |
| 46 | + if (category === 'software' && impact === '1' && urgency === '1') { |
| 47 | + alert('High impact & urgency for software incidents require manager approval before submission.'); |
| 48 | + g_form.setValue('state', ''); // Reset state to stop progression |
| 49 | + } |
| 50 | +} |
0 commit comments