diff --git a/Client-Side Components/UI Actions/Expire Timer in Flows/README.md b/Client-Side Components/UI Actions/Expire Timer in Flows/README.md new file mode 100644 index 0000000000..eeacddf70f --- /dev/null +++ b/Client-Side Components/UI Actions/Expire Timer in Flows/README.md @@ -0,0 +1,7 @@ +This UI Action adds an admin-only button to Flow Context records in ServiceNow. It is designed to expire active timers within a flow, allowing developers and testers to bypass waiting stages during sub-production testing. This helps accelerate flow validation and debugging during development cycles, especially useful during events like Hacktoberfest. + +Flows in ServiceNow often include Wait for Condition or Wait for Duration steps that can delay testing. This UI Action provides a quick way to expire those timers, enabling the flow to proceed immediately without waiting for the configured duration or condition. Features + +Adds a button labeled "Expire Timers" to Flow Context records. Visible only to users with the admin role. Executes a script to expire all active timers associated with the selected Flow Context. Ideal for sub-production environments (e.g., development, test, or staging). Speeds up flow development and validation. + +image diff --git a/Client-Side Components/UI Actions/Expire Timer in Flows/script.js b/Client-Side Components/UI Actions/Expire Timer in Flows/script.js new file mode 100644 index 0000000000..8d8d67704c --- /dev/null +++ b/Client-Side Components/UI Actions/Expire Timer in Flows/script.js @@ -0,0 +1,46 @@ +/* +This script should be placed in the UI action on the table sys_flow_context form view. +This UI action should be marked as client. +Use runClientCode() function in the Onclick field. +*/ +function runClientCode() { + + if (confirm('Are you sure you want to Expire the Timer activity ?\n\nThis Action Cannot Be Undone!')) { + //Call the UI Action and skip the 'onclick' function + gsftSubmit(null, g_form.getFormElement(), 'ExpireTimer'); //MUST call the 'Action name' set in this UI Action + } else { + return false; + } +} + +if (typeof window == 'undefined') { + ExpireTimer(); +} + +function ExpireTimer() { + var grTrigger = new GlideRecord('sys_trigger'); + grTrigger.addQuery('name', 'flow.fire'); + grTrigger.addQuery('script', 'CONTAINS', current.sys_id); + grTrigger.addQuery('state', 0); + grTrigger.setLimit(1); + grTrigger.query(); + if (grTrigger.next()) { + var grEvent = new GlideRecord('sysevent'); + grEvent.initialize(); + grEvent.setNewGuid(); + grEvent.setValue('name', 'flow.fire'); + grEvent.setValue('queue', 'flow_engine'); + grEvent.setValue('parm1', grTrigger.getValue('job_context').toString().slice(6)); + grEvent.setValue('parm2', ''); + grEvent.setValue('instance', current.sys_id); + grEvent.setValue('table', 'sys_flow_context'); + grEvent.setValue('state', 'ready'); + grEvent.setValue('process_on', new GlideDateTime().getValue()); //aka run immediately + grEvent.insert(); + grTrigger.deleteRecord(); + gs.addInfoMessage("You have chosen to end any timers related to this flow."); + } + + + action.setRedirectURL(current); +}