diff --git a/Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State/readme.md b/Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State/readme.md new file mode 100644 index 0000000000..3f6cb95b33 --- /dev/null +++ b/Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State/readme.md @@ -0,0 +1,31 @@ +📘 README — Incident State Validation (Client Script) +Overview + +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. +If a user attempts to move the state directly to Closed Complete, the system reverts the change and displays a notification. + +What This Code Does +Monitors changes to the state field on Incident form +Checks if new selection is trying to skip the Resolved step +Reverts state to its previous value when the rule is violated +Alerts the user with a clear and guided message +Refreshes the form to maintain data consistency +Usage Instructions + +Create a Client Script on the Incident table +Type: onChange +Field Name: state +Paste the script under the script section +Test by trying to directly move an Incident to Closed Complete +S +cript Requirements +State values must be configured as: +6 → Resolved +7 → Closed Complete + +Script runs only on Incident records +Must be active in applicable ITIL views +Notes for Developers +This code supports clean transition handling for ITSM workflows +Helps enforce process compliance without server-side overhead +Recommended for environments requiring strict closure governance diff --git a/Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State/script.js b/Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State/script.js new file mode 100644 index 0000000000..f423c6109c --- /dev/null +++ b/Client-Side Components/Client Scripts/Abort direct incident closure without Resolve State/script.js @@ -0,0 +1,30 @@ +function onChange(control, oldValue, newValue, isLoading, isTemplate) { + // Prevent execution during form load or when value is empty + if (isLoading || newValue === '') { + return; + } + + // Dummy values for state comparison + // Assuming: + // 6 = Resolved + // 7 = Closed Complete + var RESOLVED = 6; + var CLOSED = 7; + + // Prevent direct move to Closed without passing through Resolved + if (newValue == CLOSED && oldValue != RESOLVED) { + + // Reset to previous state + g_form.setValue('state', oldValue); + + // Show validation warning + g_form.addErrorMessage( + 'Direct closure is not allowed. Please first move the incident to Resolved state.' + ); + + // Reload page after showing error + setTimeout(function() { + location.reload(); + }, 3000); + } +}