Skip to content

Commit 8eaa2ab

Browse files
authored
Auto Priority Update based on Impact and Urgency (#2649)
* Code for Moveworks bot messages for Flow to include url links * Delete Moveworks messages html for Flow * Create script.js * Create readme.md * Create script.js * Create readme.md * Delete Client-Side Components/Client Scripts/Auto Priority Update based on Impact and Urgency/readme.md * Delete Client-Side Components/Client Scripts/Auto Priority Update based on Impact and Urgency/script.js
1 parent b139057 commit 8eaa2ab

File tree

2 files changed

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

2 files changed

+139
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
🧩 Readme : Client Script: Auto Priority Update Based on Impact and Urgency
2+
📘 Overview
3+
4+
This client script automatically updates the Priority field on the Incident form whenever the Impact or Urgency value changes.
5+
It follows the ITIL standard mapping to ensure the correct priority is always set automatically, improving data accuracy and efficiency for service desk agents.
6+
7+
⚙️ Script Details
8+
Field Value
9+
Name Auto Priority Update based on Impact and Urgency
10+
Type onChange
11+
Applies to Table Incident
12+
Applies on Fields impact, urgency
13+
UI Type All (Classic, Mobile, Workspace)
14+
Active ✅ Yes
15+
Condition Leave blank
16+
💻 Script Code
17+
// ==========================================================================
18+
// Script Name: Auto Priority Update based on Impact and Urgency
19+
// Table: Incident
20+
// Type: onChange | Fields: impact, urgency
21+
// UI Type: All
22+
// Version: 2025 Production Ready
23+
// ==========================================================================
24+
25+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
26+
// Skip execution if form is loading or field is empty
27+
if (isLoading || newValue == '') {
28+
return;
29+
}
30+
31+
// Get Impact and Urgency values
32+
var impact = g_form.getValue('impact');
33+
var urgency = g_form.getValue('urgency');
34+
35+
// Define Priority Matrix (ITIL standard)
36+
var priorityMatrix = {
37+
'1': { '1': '1', '2': '2', '3': '3' },
38+
'2': { '1': '2', '2': '3', '3': '4' },
39+
'3': { '1': '3', '2': '4', '3': '5' }
40+
};
41+
42+
// Find the new Priority
43+
var newPriority = priorityMatrix[impact]?.[urgency];
44+
45+
// Update the Priority field if valid
46+
if (newPriority) {
47+
if (g_form.getValue('priority') != newPriority) {
48+
g_form.setValue('priority', newPriority);
49+
g_form.showFieldMsg('priority', 'Priority auto-updated based on Impact and Urgency', 'info');
50+
}
51+
} else {
52+
// Optional: Clear Priority if invalid combination is selected
53+
g_form.clearValue('priority');
54+
g_form.showFieldMsg('priority', 'Invalid Impact/Urgency combination — priority cleared', 'error');
55+
}
56+
}
57+
58+
🧠 How It Works
59+
60+
The script runs automatically when Impact or Urgency changes.
61+
It checks the ITIL-based matrix to determine the correct Priority.
62+
If a valid combination is found, the Priority field updates automatically.
63+
A small info message appears to confirm the update.
64+
65+
🔢 ITIL Mapping Table
66+
Impact Urgency Resulting Priority
67+
1 (High) 1 (High) 1 (Critical)
68+
1 2 2
69+
1 3 3
70+
2 1 2
71+
2 2 3
72+
2 3 4
73+
3 1 3
74+
3 2 4
75+
3 3 5
76+
✅ Benefits
77+
78+
Automatically enforces ITIL priority standards
79+
Reduces manual effort and user errors
80+
Ensures consistency in priority calculation
81+
Compatible with Classic UI, Next Experience, and Agent Workspace
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)