From fcdae426edddff04067214a0c11d13eddef7e5ff Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:21:02 +0530 Subject: [PATCH 1/4] Created Script.js file --- .../UI Actions/Incident Cancellation/Script.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Client-Side Components/UI Actions/Incident Cancellation/Script.js diff --git a/Client-Side Components/UI Actions/Incident Cancellation/Script.js b/Client-Side Components/UI Actions/Incident Cancellation/Script.js new file mode 100644 index 0000000000..85d5aa3f88 --- /dev/null +++ b/Client-Side Components/UI Actions/Incident Cancellation/Script.js @@ -0,0 +1,13 @@ +function cancelincident() { + confirm("Do you want to cancel the incident ?"); + gsftSubmit(null, g_form.getFormElement(), 'cancel_inc'); +} +if (typeof window == "undefined") + cancellingincident(); + +function cancellingincident() { + current.state = 8; + current.work_notes = "Cancelled this incident"; + current.update(); + action.setRedirectURL(current); +} From 664c7cd8da1bb7ad6f6da16ca1332a53cb1d74e6 Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:35:33 +0530 Subject: [PATCH 2/4] Created README.md --- .../Incident Cancellation/README.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Client-Side Components/UI Actions/Incident Cancellation/README.md diff --git a/Client-Side Components/UI Actions/Incident Cancellation/README.md b/Client-Side Components/UI Actions/Incident Cancellation/README.md new file mode 100644 index 0000000000..e0b2b91950 --- /dev/null +++ b/Client-Side Components/UI Actions/Incident Cancellation/README.md @@ -0,0 +1,52 @@ +## Simplified Incident Cancellation UI Action + +## Overview +This enhancement improves the Incident Cancellation UI Action in ServiceNow by replacing an unnecessarily complex GlideModal confirmation structure with a leaner, more maintainable confirmation() dialog. +The new approach enhances code readability, reduces script overhead, and aligns with ServiceNow client–server scripting best practices. + +## Problem Statement +The previous incident cancellation UI Action used a GlideModal confirmation window, which: +- Increased code complexity with extra modal creation and rendering steps +- Complicated maintainability with mixed client-server logic +- Provided no additional usability benefit over native browser confirmation + + +## Proposed Enhancement +The enhancement simplifies the flow by using JavaScript’s built-in confirm() method for quick user confirmation and Added a work note for traceability: “Cancelled this incident.” + +## Updated Logic: +- Client-side: +Confirm with confirm() dialog before proceeding. +If confirmed, submit action via gsftSubmit() API to call the server script. + +- Server-side: +Update the incident state to "Cancelled" (state = 8). +Add a work note for traceability: “Cancelled this incident.” +Redirect the user back to the current record after completion. + +# Benefits +- Simpler and cleaner codebase +- Avoids unnecessary modal logic. +- Better maintainability +- Easier for future developers to modify or extend. +- Improved traceability +- Includes meaningful work notes for auditing. +- Aligned with ServiceNow best practices +- Maintains proper separation of client and server logic following official guidelines.​ + +## How to Use + +- Navigate to System UI → UI Actions in ServiceNow. +- Create a new UI Action on the Incident table. +### Set: +- Action name: Cancel Incident +- Client: Checked +- Onclick: cancelIncident(); +- Condition: current.state != 8 +- Add the provided client and server scripts from the script.js file +- Test the action on an incident form. + +## Issue Reference +This contribution is based on the issue titled: `Issue with UI Action Implementation for Simplified Incident Cancellation` +## Issue no: [#2299](https://github.com/ServiceNowDevProgram/code-snippets/issues/2299) +— proposed to improve readability, maintainability, and UX by using a confirmation dialog instead of a GlideModal construct. From cf6bb1d3a5e620621e81b8e932dcb9eca33abe81 Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:48:11 +0530 Subject: [PATCH 3/4] Deleting this README.md --- .../Incident Cancellation/README.md | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 Client-Side Components/UI Actions/Incident Cancellation/README.md diff --git a/Client-Side Components/UI Actions/Incident Cancellation/README.md b/Client-Side Components/UI Actions/Incident Cancellation/README.md deleted file mode 100644 index e0b2b91950..0000000000 --- a/Client-Side Components/UI Actions/Incident Cancellation/README.md +++ /dev/null @@ -1,52 +0,0 @@ -## Simplified Incident Cancellation UI Action - -## Overview -This enhancement improves the Incident Cancellation UI Action in ServiceNow by replacing an unnecessarily complex GlideModal confirmation structure with a leaner, more maintainable confirmation() dialog. -The new approach enhances code readability, reduces script overhead, and aligns with ServiceNow client–server scripting best practices. - -## Problem Statement -The previous incident cancellation UI Action used a GlideModal confirmation window, which: -- Increased code complexity with extra modal creation and rendering steps -- Complicated maintainability with mixed client-server logic -- Provided no additional usability benefit over native browser confirmation - - -## Proposed Enhancement -The enhancement simplifies the flow by using JavaScript’s built-in confirm() method for quick user confirmation and Added a work note for traceability: “Cancelled this incident.” - -## Updated Logic: -- Client-side: -Confirm with confirm() dialog before proceeding. -If confirmed, submit action via gsftSubmit() API to call the server script. - -- Server-side: -Update the incident state to "Cancelled" (state = 8). -Add a work note for traceability: “Cancelled this incident.” -Redirect the user back to the current record after completion. - -# Benefits -- Simpler and cleaner codebase -- Avoids unnecessary modal logic. -- Better maintainability -- Easier for future developers to modify or extend. -- Improved traceability -- Includes meaningful work notes for auditing. -- Aligned with ServiceNow best practices -- Maintains proper separation of client and server logic following official guidelines.​ - -## How to Use - -- Navigate to System UI → UI Actions in ServiceNow. -- Create a new UI Action on the Incident table. -### Set: -- Action name: Cancel Incident -- Client: Checked -- Onclick: cancelIncident(); -- Condition: current.state != 8 -- Add the provided client and server scripts from the script.js file -- Test the action on an incident form. - -## Issue Reference -This contribution is based on the issue titled: `Issue with UI Action Implementation for Simplified Incident Cancellation` -## Issue no: [#2299](https://github.com/ServiceNowDevProgram/code-snippets/issues/2299) -— proposed to improve readability, maintainability, and UX by using a confirmation dialog instead of a GlideModal construct. From a831662ab1b4c0c97a13153508263507af9444ad Mon Sep 17 00:00:00 2001 From: Yelugu Sriharsha <89392618+Sriharsha19@users.noreply.github.com> Date: Mon, 20 Oct 2025 20:49:48 +0530 Subject: [PATCH 4/4] Updated the README.md --- .../Incident Cancellation/README.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Client-Side Components/UI Actions/Incident Cancellation/README.md diff --git a/Client-Side Components/UI Actions/Incident Cancellation/README.md b/Client-Side Components/UI Actions/Incident Cancellation/README.md new file mode 100644 index 0000000000..13eae8596a --- /dev/null +++ b/Client-Side Components/UI Actions/Incident Cancellation/README.md @@ -0,0 +1,52 @@ +## Simplified Incident Cancellation UI Action + +## Overview +This enhancement improves the Incident Cancellation UI Action in ServiceNow by replacing an unnecessarily complex GlideModal confirmation structure with a leaner, more maintainable confirmation() dialog. +The new approach enhances code readability, reduces script overhead, and aligns with ServiceNow client–server scripting best practices. + +## Problem Statement +The previous incident cancellation UI Action used a GlideModal confirmation window, which: +- Increased code complexity with extra modal creation and rendering steps +- Complicated maintainability with mixed client-server logic +- Provided no additional usability benefit over native browser confirmation + + +## Proposed Enhancement +The enhancement simplifies the flow by using JavaScript’s built-in confirm() method for quick user confirmation and Added a work note for traceability: “Cancelled this incident.” + +## Updated Logic: +- Client-side: +Confirm with confirm() dialog before proceeding. +If confirmed, submit action via gsftSubmit() API to call the server script. + +- Server-side: +Update the incident state to "Cancelled" (state = 8). +Add a work note for traceability: “Cancelled this incident.” +Redirect the user back to the current record after completion. + +# Benefits +- Simpler and cleaner codebase +- Avoids unnecessary modal logic. +- Better maintainability +- Easier for future developers to modify or extend. +- Improved traceability +- Includes meaningful work notes for auditing. +- Aligned with ServiceNow best practices +- Maintains proper separation of client and server logic following official guidelines.​ + +## How to Use + +- Navigate to System UI → UI Actions in ServiceNow. +- Create a new UI Action on the Incident table. +### Set: +- Action name: Cancel Incident +- Client: Checked +- Onclick: cancelIncident(); +- Condition: current.state != 8 && (current.state == '1' || current.state == '2' || current.state == '3'); +- Add the provided client and server scripts from the script.js file +- Test the action on an incident form. + +## Issue Reference +This contribution is based on the issue titled: `Issue with UI Action Implementation for Simplified Incident Cancellation` +## Issue no: [#2299](https://github.com/ServiceNowDevProgram/code-snippets/issues/2299) +— proposed to improve readability, maintainability, and UX by using a confirmation dialog instead of a GlideModal construct.