Skip to content

Commit 71ce1e5

Browse files
authored
Create script.js
1 parent 1bd225c commit 71ce1e5

File tree

1 file changed

+56
-0
lines changed
  • Client-Side Components/Client Scripts/Auto Priority Update based on Impact and Urgency

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ==========================================================================
2+
// Script Name: Auto Priority Update based on Impact and Urgency
3+
// Table: Incident (or any Task-based table)
4+
// Type: onChange | Fields: impact, urgency
5+
// UI Type: All
6+
// ==========================================================================
7+
8+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
9+
// Prevent the script from running when the form loads or when the field is empty
10+
if (isLoading || newValue == '') {
11+
return;
12+
}
13+
14+
// ----------------------------------------------------------------------
15+
// Step 1: Fetch field values from the form
16+
// ----------------------------------------------------------------------
17+
var impact = g_form.getValue('impact'); // e.g., 1 - High, 2 - Medium, 3 - Low
18+
var urgency = g_form.getValue('urgency'); // e.g., 1 - High, 2 - Medium, 3 - Low
19+
20+
// ----------------------------------------------------------------------
21+
// Step 2: Define the ITIL-based Priority Matrix
22+
// ----------------------------------------------------------------------
23+
// Each row represents "Impact", and each column represents "Urgency"
24+
// The resulting value sets the "Priority"
25+
var priorityMatrix = {
26+
'1': { '1': '1', '2': '2', '3': '3' }, // Impact = High
27+
'2': { '1': '2', '2': '3', '3': '4' }, // Impact = Medium
28+
'3': { '1': '3', '2': '4', '3': '5' } // Impact = Low
29+
};
30+
31+
// ----------------------------------------------------------------------
32+
// Step 3: Determine the new priority based on selected Impact/Urgency
33+
// ----------------------------------------------------------------------
34+
var newPriority = priorityMatrix[impact]?.[urgency]; // optional chaining prevents errors
35+
36+
// ----------------------------------------------------------------------
37+
// Step 4: Update the Priority field and inform the user
38+
// ----------------------------------------------------------------------
39+
if (newPriority) {
40+
// Only update if priority is different from current value
41+
if (g_form.getValue('priority') != newPriority) {
42+
g_form.setValue('priority', newPriority);
43+
44+
// Show message (works in both Classic UI and Next Experience)
45+
g_form.showFieldMsg('priority', 'Priority auto-updated based on Impact and Urgency', 'info');
46+
}
47+
} else {
48+
// Optional: clear priority if invalid combination is selected
49+
g_form.clearValue('priority');
50+
g_form.showFieldMsg('priority', 'Invalid Impact/Urgency combination — priority cleared', 'error');
51+
}
52+
53+
// ----------------------------------------------------------------------
54+
// End of Script
55+
// ----------------------------------------------------------------------
56+
}

0 commit comments

Comments
 (0)