Skip to content

Commit af47e27

Browse files
authored
Prevent Direct Closure of Incidents Without Resolved State Transition (#2610)
* Code for Moveworks bot messages for Flow to include url links * Create script.js * Create readme.md * Delete Moveworks messages html for Flow
1 parent 7078253 commit af47e27

File tree

2 files changed

+61
-0
lines changed
  • Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State

2 files changed

+61
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
📘 README — Incident State Validation (Client Script)
2+
Overview
3+
4+
This Client Script enforces the correct ITIL incident lifecycle by preventing users from directly closing an incident without first transitioning it through the Resolved state.
5+
If a user attempts to move the state directly to Closed Complete, the system reverts the change and displays a notification.
6+
7+
What This Code Does
8+
Monitors changes to the state field on Incident form
9+
Checks if new selection is trying to skip the Resolved step
10+
Reverts state to its previous value when the rule is violated
11+
Alerts the user with a clear and guided message
12+
Refreshes the form to maintain data consistency
13+
Usage Instructions
14+
15+
Create a Client Script on the Incident table
16+
Type: onChange
17+
Field Name: state
18+
Paste the script under the script section
19+
Test by trying to directly move an Incident to Closed Complete
20+
S
21+
cript Requirements
22+
State values must be configured as:
23+
6 → Resolved
24+
7 → Closed Complete
25+
26+
Script runs only on Incident records
27+
Must be active in applicable ITIL views
28+
Notes for Developers
29+
This code supports clean transition handling for ITSM workflows
30+
Helps enforce process compliance without server-side overhead
31+
Recommended for environments requiring strict closure governance
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
2+
// Prevent execution during form load or when value is empty
3+
if (isLoading || newValue === '') {
4+
return;
5+
}
6+
7+
// Dummy values for state comparison
8+
// Assuming:
9+
// 6 = Resolved
10+
// 7 = Closed Complete
11+
var RESOLVED = 6;
12+
var CLOSED = 7;
13+
14+
// Prevent direct move to Closed without passing through Resolved
15+
if (newValue == CLOSED && oldValue != RESOLVED) {
16+
17+
// Reset to previous state
18+
g_form.setValue('state', oldValue);
19+
20+
// Show validation warning
21+
g_form.addErrorMessage(
22+
'Direct closure is not allowed. Please first move the incident to Resolved state.'
23+
);
24+
25+
// Reload page after showing error
26+
setTimeout(function() {
27+
location.reload();
28+
}, 3000);
29+
}
30+
}

0 commit comments

Comments
 (0)