- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 03:35 AM
Hi
I have one custom table and i am inserting record on the table whenever changing state is pending the Incident table
1. Once Record is created on my custom table one workflow will run on the record
2. if they changing the state form pending to active then again changing active to Pending state in incident table means another one record will insert in my custom table
in this case i want to cancel my previous record workflow
How to achieve this..?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 04:15 AM
Hi Ashutosh,
Can i do like this,
I have running one Before Insert BR on my custom table and running this script....
var rec = new GlideRecord('on_hold_state');
rec.addQuery('number', current.number);
rec.query();
if (rec.next()) {
var workflow = new global.Workflow();
workflow.cancel(rec);
gs.info("Existing Recors is " + rec.sys_id);
}
actually this is working but i just want to know whether this is correct method or not
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 07:51 AM
Thank you. i'm going to use this only

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2018 07:53 AM
If you dont mind can you mark answer as correct and close this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2020 12:39 AM
Thanks, this post helped me as well.
/Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2019 08:33 PM
Here is a simple piece of code to cancel a workflow.
var gr = new GlideRecord('wf_context');
gr.get(<workflowcontext_you_want_to_cancel>);
new Workflow().cancelContext(gr);
var wgr = new GlideRecord("wf_context");
wgr.addQuery("workflow_version",'a899f32edb5ff300d0f770c08c96197c'); // Add this if you want to cancel all active workflow contexts related to a given workflow.
wgr.addQuery("started_by",'e48daa51dbe5a700d0f770c08c961931'); // add the sysid of a user who started the workflow
wgr.query();
while(wgr.next()){
gs.print(wgr.id.number);
var gr = new GlideRecord('wf_context');
gr.get(wgr.sys_id);
new Workflow().cancelContext(gr);
}