Skip to content

Commit 565439d

Browse files
authored
Create script.js
1 parent 5d925c3 commit 565439d

File tree

1 file changed

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

1 file changed

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

0 commit comments

Comments
 (0)