Continue Workflow if either task is completed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 06:05 AM
In my Workflow, I would like to continue if either one of two tasks is completed. Branch/Join doesn't seem to be the correct answer since it requires something to happen to both tasks. Pointing both boxes to the next step causes inconsistent cancelling of the workflow if one task finishes and the other is cancelled. Please help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 06:18 AM
Hi Juile,
service-now.com provides a very robust and simple way to manage your tasks and approvals (among other things) through its graphical workflow engine. It is very common to use graphical workflow to help facilitate some change management process within your organization. One common requirement in change management is to be able to cancel or close the change request at any time during the process. “Simple”, you say. “Just allow the user to change the value of the ‘State’ field to ‘Closed’.”
You would not be incorrect in saying something like that, but you would be forgetting about part of the problem with closing or canceling a change request or other task ticket. What if the attached workflow(s) still think that the change request and its associated tasks and approvals are still in progress? Should the attached workflow context(s) continue to run indefinitely? If your workflow doesn’t have a way to know about the completion of the change request then it will continue to run (or more likely just sit and be forgotten).
The answer to this problem is actually pretty simple. Service-now.com comes with several out-of-box workflow utility functions defined under ‘System Definition -> Script Includes’ that can be helpful in situations like these. While you don’t want to modify these script includes, it is probably a good idea as a Service-now administrator to become familiar with the tools and functions there. One of the functions in the ‘Workflow’ script include is called ‘cancel’. It can be used to cancel any running workflow activities for a given record. This script could be called from a UI action button, another workflow, or a business rule. You just need to be able to tell the function what GlideRecord should have its workflows canceled. The example below shows how you could create a business rule to cancel all running workflows for a given record if the ‘active’ field changed to ‘false’. The cancellation in the example below happens for the ‘current’ GlideRecord object (which is the current record being updated).
Name: Cancel workflows
When: After
Insert: True
Update: True
Condition: current.active.changesTo(false)
Script:
new Workflow().cancel(current);
var flows = new Workflow().getRunningFlows(current);
while(flows.next()){
//Check for associated workflows by name
if(flows.workflow_version.getDisplayValue() == 'Routine Change'){
//Cancel the workflow context
new Workflow().cancelContext(flows);
}
}
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 06:20 AM
Hi Julie,
It sounds like you can have both catalog tasks flow to the next activity and if either one completes, it will move on and the other task that is not complete can still be worked, but the flow is not waiting on it. Am I understanding your need? The Join's usage is to ensure that the flow doesn't move on until things are done, but you don't have to use it. The problem you could run into is that the workflow might complete with a task that has been created but not finished. You may want to clean up the task by closing it before ending the work flow if the task is not required before the flow ends. Does this help/make sense?
Thanks,
Trena

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2019 06:40 AM
Hi again Julie,
I just re-read your question and you indicated that you have tried my solution that I identified above but you receive inconsistent canceling of the tasks and that is due to the workflow ending before the other task is complete. Maybe try having both tasks tied to the activity that can be done when either one completes and also have them tied (at the same time) to a join and have the final activity (before it moves to end) also tied to the join (3 activities are now tied to the join) and then remove the connection from the last activity tied to the end and have the join tied to the end. Hopefully this will prevent the workflow from ending before all 3 flows complete. Let me know if this works.