Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
🧩 Readme : Client Script: Auto Priority Update Based on Impact and Urgency
📘 Overview

This client script automatically updates the Priority field on the Incident form whenever the Impact or Urgency value changes.
It follows the ITIL standard mapping to ensure the correct priority is always set automatically, improving data accuracy and efficiency for service desk agents.

⚙️ Script Details
Field Value
Name Auto Priority Update based on Impact and Urgency
Type onChange
Applies to Table Incident
Applies on Fields impact, urgency
UI Type All (Classic, Mobile, Workspace)
Active ✅ Yes
Condition Leave blank
💻 Script Code
// ==========================================================================
// Script Name: Auto Priority Update based on Impact and Urgency
// Table: Incident
// Type: onChange | Fields: impact, urgency
// UI Type: All
// Version: 2025 Production Ready
// ==========================================================================

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Skip execution if form is loading or field is empty
if (isLoading || newValue == '') {
return;
}

// Get Impact and Urgency values
var impact = g_form.getValue('impact');
var urgency = g_form.getValue('urgency');

// Define Priority Matrix (ITIL standard)
var priorityMatrix = {
'1': { '1': '1', '2': '2', '3': '3' },
'2': { '1': '2', '2': '3', '3': '4' },
'3': { '1': '3', '2': '4', '3': '5' }
};

// Find the new Priority
var newPriority = priorityMatrix[impact]?.[urgency];

// Update the Priority field if valid
if (newPriority) {
if (g_form.getValue('priority') != newPriority) {
g_form.setValue('priority', newPriority);
g_form.showFieldMsg('priority', 'Priority auto-updated based on Impact and Urgency', 'info');
}
} else {
// Optional: Clear Priority if invalid combination is selected
g_form.clearValue('priority');
g_form.showFieldMsg('priority', 'Invalid Impact/Urgency combination — priority cleared', 'error');
}
}

🧠 How It Works

The script runs automatically when Impact or Urgency changes.
It checks the ITIL-based matrix to determine the correct Priority.
If a valid combination is found, the Priority field updates automatically.
A small info message appears to confirm the update.

🔢 ITIL Mapping Table
Impact Urgency Resulting Priority
1 (High) 1 (High) 1 (Critical)
1 2 2
1 3 3
2 1 2
2 2 3
2 3 4
3 1 3
3 2 4
3 3 5
✅ Benefits

Automatically enforces ITIL priority standards
Reduces manual effort and user errors
Ensures consistency in priority calculation
Compatible with Classic UI, Next Experience, and Agent Workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//Auto Priority Update based on Impact and Urgency

// ==========================================================================
// Script Name: Auto Priority Update based on Impact and Urgency
// Table: Incident (or any Task-based table)
// Type: onChange | Fields: impact, urgency
// UI Type: All
// ==========================================================================

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Prevent the script from running when the form loads or when the field is empty
if (isLoading || newValue == '') {
return;
}

// ----------------------------------------------------------------------
// Step 1: Fetch field values from the form
// ----------------------------------------------------------------------
var impact = g_form.getValue('impact'); // e.g., 1 - High, 2 - Medium, 3 - Low
var urgency = g_form.getValue('urgency'); // e.g., 1 - High, 2 - Medium, 3 - Low

// ----------------------------------------------------------------------
// Step 2: Define the ITIL-based Priority Matrix
// ----------------------------------------------------------------------
// Each row represents "Impact", and each column represents "Urgency"
// The resulting value sets the "Priority"
var priorityMatrix = {
'1': { '1': '1', '2': '2', '3': '3' }, // Impact = High
'2': { '1': '2', '2': '3', '3': '4' }, // Impact = Medium
'3': { '1': '3', '2': '4', '3': '5' } // Impact = Low
};

// ----------------------------------------------------------------------
// Step 3: Determine the new priority based on selected Impact/Urgency
// ----------------------------------------------------------------------
var newPriority = priorityMatrix[impact]?.[urgency]; // optional chaining prevents errors

// ----------------------------------------------------------------------
// Step 4: Update the Priority field and inform the user
// ----------------------------------------------------------------------
if (newPriority) {
// Only update if priority is different from current value
if (g_form.getValue('priority') != newPriority) {
g_form.setValue('priority', newPriority);

// Show message (works in both Classic UI and Next Experience)
g_form.showFieldMsg('priority', 'Priority auto-updated based on Impact and Urgency', 'info');
}
} else {
// Optional: clear priority if invalid combination is selected
g_form.clearValue('priority');
g_form.showFieldMsg('priority', 'Invalid Impact/Urgency combination — priority cleared', 'error');
}

// ----------------------------------------------------------------------
// End of Script
// ----------------------------------------------------------------------
}
Loading