Skip to content

Commit 580f8c5

Browse files
authored
Expire Timers in Flows (#2314)
* README.md * Create script.js
1 parent 55efc05 commit 580f8c5

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
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.
2+
3+
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
4+
5+
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.
6+
7+
<img width="1584" height="165" alt="image" src="https://github.com/user-attachments/assets/64d02ab2-de5b-48b6-82ac-d00771f43898" />
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
This script should be placed in the UI action on the table sys_flow_context form view.
3+
This UI action should be marked as client.
4+
Use runClientCode() function in the Onclick field.
5+
*/
6+
function runClientCode() {
7+
8+
if (confirm('Are you sure you want to Expire the Timer activity ?\n\nThis Action Cannot Be Undone!')) {
9+
//Call the UI Action and skip the 'onclick' function
10+
gsftSubmit(null, g_form.getFormElement(), 'ExpireTimer'); //MUST call the 'Action name' set in this UI Action
11+
} else {
12+
return false;
13+
}
14+
}
15+
16+
if (typeof window == 'undefined') {
17+
ExpireTimer();
18+
}
19+
20+
function ExpireTimer() {
21+
var grTrigger = new GlideRecord('sys_trigger');
22+
grTrigger.addQuery('name', 'flow.fire');
23+
grTrigger.addQuery('script', 'CONTAINS', current.sys_id);
24+
grTrigger.addQuery('state', 0);
25+
grTrigger.setLimit(1);
26+
grTrigger.query();
27+
if (grTrigger.next()) {
28+
var grEvent = new GlideRecord('sysevent');
29+
grEvent.initialize();
30+
grEvent.setNewGuid();
31+
grEvent.setValue('name', 'flow.fire');
32+
grEvent.setValue('queue', 'flow_engine');
33+
grEvent.setValue('parm1', grTrigger.getValue('job_context').toString().slice(6));
34+
grEvent.setValue('parm2', '');
35+
grEvent.setValue('instance', current.sys_id);
36+
grEvent.setValue('table', 'sys_flow_context');
37+
grEvent.setValue('state', 'ready');
38+
grEvent.setValue('process_on', new GlideDateTime().getValue()); //aka run immediately
39+
grEvent.insert();
40+
grTrigger.deleteRecord();
41+
gs.addInfoMessage("You have chosen to end any timers related to this flow.");
42+
}
43+
44+
45+
action.setRedirectURL(current);
46+
}

0 commit comments

Comments
 (0)