Skip to content

Commit 121806c

Browse files
authored
Onchange validation client script
Validates the onchange client script based on the category, priority and urgency
1 parent ba1c836 commit 121806c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)