|
| 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