- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 07:18 AM
Hello i am creating a business rule that when triggered it stops the current workflow and will start a different workflow. Any ideas on how to achieve this? Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 07:25 AM
Hi
To start a new workflow and attach to the ticket
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert'); //gr is the record
To cancel the workflow
var w = new Workflow();
var gr = new GlideRecord(‘wf_context’);
if (gr.get(current.context)) // current is the record here
w.cancelContext(gr);
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 07:23 AM
Hi,
Can you refer this link to understand.
https://community.servicenow.com/community?id=community_question&sys_id=7f864b25db1cdbc01dcaf3231f9619b3
Please mark as correct answer if it helped.
Regards,
Suresh.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 07:25 AM
Hi
To start a new workflow and attach to the ticket
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert'); //gr is the record
To cancel the workflow
var w = new Workflow();
var gr = new GlideRecord(‘wf_context’);
if (gr.get(current.context)) // current is the record here
w.cancelContext(gr);
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 07:43 AM
Hi,
like this
// cancel old
var flows = new Workflow().getRunningFlows(current);
while(flows.next()) {
new Workflow().cancelContext(flows);
}
// attach the new one
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName('give the workflow name'), current, 'update');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2022 08:09 AM
you can try this
// to cancel old
var wf= new Workflow().getRunningFlows(current);
while(wf.next()) {
new Workflow().cancelContext(wf);
}
// to attach the new one
var wfl = new Workflow();
wfl.startFlow(wfl.getWorkflowFromName('workflow name'), current, 'update');