diff --git a/Client-Side Components/UI Actions/Kill flow timers/README.md b/Client-Side Components/UI Actions/Kill flow timers/README.md new file mode 100644 index 0000000000..476d2c07d9 --- /dev/null +++ b/Client-Side Components/UI Actions/Kill flow timers/README.md @@ -0,0 +1,12 @@ +# UI Action to kill flow timers + +UI page that shows you all timers that a flow context [sys_flow_context] is waiting for. Shows sys_id of the sys_trigger, the datetime when the wait will finish and how long until that time. Select the checkbox and submit the modal form to kill that timer. + +## How to use + +1. Create ui action on [sys_flow_context] and input the script from *UI action.js* in the script field. Check client and set Onclick as *openTimerDialog()* +2. Create ui page with name *timer_kill_dialog* and copy the HTML, client script and processing script from the *UI page for ui action.js* file +3. Navigate to active flow context that is waiting for timers and click the ui action from step 1 and kill timer/s. Flow will progress as soon as the flow engine processes the flow.fire events + +![image](timer.png) + diff --git a/Client-Side Components/UI Actions/Kill flow timers/UI action.js b/Client-Side Components/UI Actions/Kill flow timers/UI action.js new file mode 100644 index 0000000000..7ea8c6f32b --- /dev/null +++ b/Client-Side Components/UI Actions/Kill flow timers/UI action.js @@ -0,0 +1,9 @@ +//Onlick: openTimerDialog() + +//open dialog using glidemodal and timer_kill_dialog ui page, pass in current sys_flow_context sysid +function openTimerDialog() { + var dialog = new GlideModal("timer_kill_dialog"); + dialog.setTitle("Kill timers"); + dialog.setPreference('sysparm_id', g_form.getUniqueValue()); + dialog.render(); +} diff --git a/Client-Side Components/UI Actions/Kill flow timers/UI page for ui action.js b/Client-Side Components/UI Actions/Kill flow timers/UI page for ui action.js new file mode 100644 index 0000000000..764637e348 --- /dev/null +++ b/Client-Side Components/UI Actions/Kill flow timers/UI page for ui action.js @@ -0,0 +1,100 @@ +//name: timer_kill_dialog + +//HTML: + + + + // executed server side, gets wait jobs for current flow context and returns object with information about timers + var array = []; + var waitJob = new GlideRecord("sys_trigger"); + waitJob.addQuery("state", "0") + .addCondition("name", "flow.fire") + .addCondition("script", "CONTAINS", RP.getParameterValue("sysparm_id")); + waitJob.query(); + while (waitJob.next()) { + var obj = {}; + obj.sys_id = waitJob.getUniqueValue(); + obj.waitUntil = waitJob.getValue("next_action"); + var now = new GlideDateTime() + obj.timeLeft = GlideDateTime.subtract(now, new GlideDateTime(waitJob.getValue("next_action"))).getDisplayValue() + array.push(obj) + } + array; + + + + + + + +
+ + + + + + + + + + + + + + + + + +
timer sys_idnext actiontime leftkill?
+ ${jvar_timer.sys_id} + + ${jvar_timer.waitUntil} + + ${jvar_timer.timeLeft} + + + +
+ +
+
+
+ +//Client script: +// handler for clicking ok on modal. gathers the sys_ids for the timers that have checked checkbox +function okDialog() { + var c = gel('sysids'); + var sysids = []; + $j('input[type="checkbox"]:checked').each(function () { + var checkboxId = $j(this).attr('id').replace("ni.", ""); + sysids.push(checkboxId); + }); + c.value = sysids.toString(); + return true; +} + +//Processing script: +// queries for timer jobs and sets the job and new flow.fire event to process instantly -> timer on flow completes +var waitJob = new GlideRecord("sys_trigger"); +waitJob.addQuery("sys_id", "IN", sysids); +waitJob.query(); +while (waitJob.next()) { + var currentScript = waitJob.getValue("script"); + var now = new GlideDateTime().getValue(); + var replaceScript = currentScript.replace(/gr\.setValue\('process_on',\s*'[^']*'\)/, "gr.setValue('process_on','" + now + "')"); + waitJob.setValue("script", replaceScript); + waitJob.setValue("next_action", now); + waitJob.update(); +} +//redirect back to bottom of nav stack +var urlOnStack = GlideSession.get().getStack().bottom(); +response.sendRedirect(urlOnStack); diff --git a/Client-Side Components/UI Actions/Kill flow timers/timer.png b/Client-Side Components/UI Actions/Kill flow timers/timer.png new file mode 100644 index 0000000000..b9e099b559 Binary files /dev/null and b/Client-Side Components/UI Actions/Kill flow timers/timer.png differ