Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Wait for first workflow to finish before starting second

troubleshooter3
Level 2
Level 2

This is very straight forward situation where my first workflow sets up some values and second workflow uses those values to do something. My problem is 1st workflow takes time to set up those values and second workflow is unable to get the values 1st workflow sets up. How can I make sure to wait till 1st Workflow is completed before invoking second. Below is my code, It is doing the trick but I am not sure if thats the right way.

 

while (wfSession.getWorkflows(new String[] { "RUNNING" }).length != 0) {
LOG.info("Waiting to Finish");

}

 

In above solution I am getting count of workflow associated with current session with status Running. once its zero I exit the loop. My concern is what if workflow keeps in running state due to an error or any other thing.

 

 

1 Accepted Solution
Nupur_Jain
Correct answer by
Community Advisor
Community Advisor

HI @troubleshooter3 

 

you have two different workflows, why not start second workflow model when first workflow model finishes. for this, there is "Container Step" component which you can drop as first workflow's last step and configure which workflow you want to start next.

 

Screenshot from 2020-08-24 15-42-02.png

Screenshot from 2020-08-24 15-43-34.png

 

Refer https://docs.adobe.com/content/help/en/experience-manager-64/developing/extending-aem/extending-work... to understand container step.

 

Hope it helps!

Thanks!

Nupur

 

 

View solution in original post

7 Replies
Shashi_Mulugu
Community Advisor
Community Advisor

@troubleshooter3 how are invoking these workflows? If workflow 1 is setting some value, you can configure a launcher or event listener for those node properties set or updated by workflow1 and trigger workflow 2

Vaibhavi_Gowda
Community Advisor
Community Advisor

Hi @troubleshooter3 , 

Like you mentioned below code is one of the ways to get the status of running workflow. 

while (wfSession.getWorkflows(new String[] { "RUNNING" }).length != 0) {
LOG.info("Waiting to Finish");

}

But if we triggering another workflow based on first workflow outcome, we would have achieved this in a single workflow.

You can split your processing steps to compute both the logic where you can execute the dependent step once parent step is completed. 

Arun_Patidar
Community Advisor
Community Advisor

Why don't you run second workflow from first workflow after first workflow finish the processing.

You can run any workflow either via code or use container to include another workflow within a workflow.

Nikhil-Kumar
Community Advisor
Community Advisor

@troubleshooter3 
Customize the 1st workflow by adding a step at the end of the first workflow where it executes the second one. 

Nupur_Jain
Correct answer by
Community Advisor
Community Advisor

HI @troubleshooter3 

 

you have two different workflows, why not start second workflow model when first workflow model finishes. for this, there is "Container Step" component which you can drop as first workflow's last step and configure which workflow you want to start next.

 

Screenshot from 2020-08-24 15-42-02.png

Screenshot from 2020-08-24 15-43-34.png

 

Refer https://docs.adobe.com/content/help/en/experience-manager-64/developing/extending-aem/extending-work... to understand container step.

 

Hope it helps!

Thanks!

Nupur

 

 

View solution in original post

troubleshooter3
Level 2
Level 2
Thanks I appreciate your answer, I am not sure if that will work for me, since I am triggering the OOTB workflows from java code and I donot have control to those workflows.
Nupur_Jain
Community Advisor
Community Advisor

Hi @troubleshooter3 

 

if thats the case, I think you should register Event listener for the modification of node. Once the event gets triggered, you can call second  workflow on the onEvent method of the java event class.

 

Refer https://helpx.adobe.com/experience-manager/using/aem64_event_listener.html to read more about AEM event capturing in java.

 

Thanks,

Nupur