In this guest blog post from our community member Irta Lanka, you will learn how to launch a workflow from another workflow and some of the possibilities that opens.
During the past year or so we have encountered a few use cases where starting a workflow from another workflow would have been helpful. Mario implemented that functionality some months ago but I never got around to merging it into coreBOS as we found alternative ways to implement the requests. The past month Irta ran into another use case and, although she also found another way of solving the requirement launching the workflow as a scheduled task, I dug up some time to get the Launch Workflow workflow task into coreBOS so Irta could use it to implement her requirement. I don't remember the use cases we needed this task for, but seeing what we have done I think we have opened a world of possibilities with this task. For the moment, read on to enjoy the guest post and learn how we can implement loops in coreBOS workflow system!! Thanks Irta and Mario.
A new Type of Task has been added this month: Launch Workflow task. This is a powerful and very useful implementation.
There are many cases in which a loop is needed, so Launch Workflow is the best solution for these cases. Now we will be able to loop one or more Workflow Tasks until a specified condition is met.
Like other tasks, you will find it at the presented screen where you add the tasks for the workflow:
The Summary and Conditions blocks are the same as in other task types. The part that changes is the Task Operations block. Let’s explain in detail each one of the labels and values we fill in during configuration:
The system needs to create for us Timecontrol records based on the Number of Days the employee has requested at a Leave Request record.
This is a Leave Request record, the initial status is Requested and Number of days in total is 7 (weekends and festivities included). We want that when the status changes to Approved, a workflow Create Entity (Timecontrol) will be triggered as many times as the Number of Days.
Let’s continue with the creation of the workflows:
The first workflow, the Trigger Workflow, will be the one that triggers the main workflow, which will do all the work for us.
Inside the task of type Launch Workflow, we have configured the workflow we want to be executed at Execute This Workflow operation On Current Record (the record triggering the Trigger Workflow).
In the second workflow, the worker or Main Workflow, we put all the tasks we want to be done on every execution of this workflow.
To avoid an infinite loop of workflow executions we should set a stop condition. In this case, the workflow is going to be executed until the Number of Days has decreased to 0.
isholidaydate(date, saturdayisholiday, holidays)
function added recently)The main workflow should be set to System. Mass Action to reduce the possibility of launching it individually and causing an infinite loop. Normally, this type of workflow will be run by a "trigger" workflow. You CAN launch any workflow using this new task
The Employee creates a request, where he puts the dates From and To and the Leave Type he is requesting. The Status is set by default to Requested, Is Holiday is set to Yes and Number of Days are calculated using a workflow On the first Save.
After the request is Approved, we can see at Timecontrol module the records created: (Dates 2021-10-31 and 2021-11-01 are excluded as they fall respectively on Sunday and holiday)
Now we can see at the Leave Request record that Number of Days is 0
Isholidaydate(date, saturdayisholiday, holidays)
is a new Expression Function added also this month.
It is a Boolean function, which returns True if the given date falls on a weekend or holiday. We have the possibility to consider Saturday as a workday or not. In the previous use case, we have used this function to control if the Leave date the Employee has requested is a holiday or not. If it’s a holiday, Timecontrol record will not be created.
This use case has been done using Invoke Custom Function but instead, now we can use Launch Workflow task, which will make it easier to implement and it doesn’t need developer resources.
The records in the QR Codes module will be created on the first save of the responsible InventoryDetails record. We also need to loop on the quantity field of InventoryDetails in order to create the necessary number of QR Codes.
The steps we take to resolve this task using Launch Workflow:
Closing Notes
Happy Fourth of July!
Photo by Ray Hennessy on Unsplash