# Come back from eventSubprocess to the main process

**URL:** <https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070>\
**Category:** Discussion & Questions\
**Created:** [December 21, 2021, 10:39pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070 "2021-12-21T22:39:33Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![singlash](https://forum.camunda.io/user_avatar/forum.camunda.io/singlash/32/12503_2.png) [@singlash](https://forum.camunda.io/u/singlash)\
**Post date:** [December 21, 2021, 10:39pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/1 "2021-12-21T22:39:33Z")

</div>

Hi, How do I come back to the main process after I finish my event subprocess? For the embedded subprocess, we can continue the flow automatically or some boundary event. But events I have could happen in multiple places of the process, I cannot directly declare the embedded subprocess.  
Or, is there any way to catch a message any time before a certain message catch event(or between two message catch events)?  
Two things that I tried below. For the first, it’s duplicate. It’s hard to achieve “any time”. For the second, I cannot go back to the main process.  
[test1.bpmn](https://forum.camunda.io/uploads/short-url/oOgX8BnaBdB8Yaea6gwpHe06rjE.bpmn) (12.2 KB)  
[test2.bpmn](https://forum.camunda.io/uploads/short-url/o9KqU0Km1Ap7VolD4fmjP2yoW0X.bpmn) (6.4 KB)

---

<div class="post-metadata">

**Author:** ![Ingo\_Richtsmeier](https://forum.camunda.io/user_avatar/forum.camunda.io/ingo_richtsmeier/32/25968_2.png) [@Ingo\_Richtsmeier](https://forum.camunda.io/u/Ingo_Richtsmeier)\
**Post date:** [December 22, 2021, 7:39am UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/2 "2021-12-22T07:39:36Z")

</div>

Hi @singlash,

there is no direct way to come back from an event subprocess to the main process. If you have an interrupting event subprocess, the main process cannot continue by default.

A non-interrupting event subprocess starts a new token that is independent from the main process token. Both tokens will continue to their end events independently. The main process instance is completed when all tokens reached an end event.

Hope this helps, Ingo

---

<div class="post-metadata">

**Author:** ![singlash](https://forum.camunda.io/user_avatar/forum.camunda.io/singlash/32/12503_2.png) [@singlash](https://forum.camunda.io/u/singlash)\
**Post date:** [December 22, 2021, 6:20pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/3 "2021-12-22T18:20:53Z")

</div>

Thank you so much for helping!  
Is there any way to go out of the main flow when a certain condition is met or a message is received and go back when the extra flow has been done? like an event-based gateway in multiple places, but I want them to branch to do the same task.

---

<div class="post-metadata">

**Author:** ![hassang](https://forum.camunda.io/user_avatar/forum.camunda.io/hassang/32/16498_2.png) [@hassang](https://forum.camunda.io/u/hassang)\
**Post date:** [December 22, 2021, 7:22pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/4 "2021-12-22T19:22:27Z")

</div>

Hi @singlash,

It would be great if you can provide an example of your use case.

But it looks like **call activity** should fulfill your need if place(s) of the condition to be met is known.

---

<div class="post-metadata">

**Author:** ![singlash](https://forum.camunda.io/user_avatar/forum.camunda.io/singlash/32/12503_2.png) [@singlash](https://forum.camunda.io/u/singlash)\
**Post date:** [December 22, 2021, 9:01pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/5 "2021-12-22T21:01:03Z")

</div>

Hi, Thanks for suggesting. I’ve put two bpmn approaches above.  
For example, I want to listen to message3 only before message2.  
For the first approach, it has many duplicates and is hard to limit stage.  
For the second approach, I can manually check the stage when sending messages to check if it’s appropriate. But I’m unable to resume the original process after the subprocess is done.  
The problem is that I want to wait for a message catch event in a range instead of a single point.

---

<div class="post-metadata">

**Author:** ![hassang](https://forum.camunda.io/user_avatar/forum.camunda.io/hassang/32/16498_2.png) [@hassang](https://forum.camunda.io/u/hassang)\
**Post date:** [December 23, 2021, 4:42am UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/6 "2021-12-23T04:42:14Z")

</div>

Hi @singlash,

I can see from your first model “test1” that places of waiting events are known so if you have some reusable logic following message3 then you can encapsulate it in a separate process to be called by a call activity.

---

<div class="post-metadata">

**Author:** ![singlash](https://forum.camunda.io/user_avatar/forum.camunda.io/singlash/32/12503_2.png) [@singlash](https://forum.camunda.io/u/singlash)\
**Post date:** [December 27, 2021, 4:01pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/7 "2021-12-27T16:01:11Z")

</div>

But that means that I need a gateway whenever it’s possible. If I have more message(stages), there will be a lot of gateways

---

<div class="post-metadata">

**Author:** ![Nele](https://forum.camunda.io/user_avatar/forum.camunda.io/nele/32/11313_2.png) [@Nele](https://forum.camunda.io/u/Nele)\
**Post date:** [December 27, 2021, 5:20pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/8 "2021-12-27T17:20:41Z")

</div>

Hey @singlash,

as soon as message 3 arrives you want the main process to pause?  
If the tasks can run in parallel it is possible to use the event subprocess with a non interrupting message start event like it was mentioned already:  
[test2.bpmn](https://forum.camunda.io/uploads/short-url/b8lqsHmt8LgwtHRIxcCfzX7ssug.bpmn) (6.4 KB)

If you need to pause the main flow and decide every-time you received message 3 if you want to go back to the main flow like in your example 1 it is hard to model that from the BPMN standard. And As suggested already you would need to model event-based gateways.

I am not sure if your logic allows it but if possible you could always come back to the same event based gateway:  
[test1.bpmn](https://forum.camunda.io/uploads/short-url/AjpTMkvQqvdAGSliKMpF3Y4u4fP.bpmn) (9.9 KB)

Obviously that has some drawbacks too as now the happy path is not that visible anymore. But it would work technically.

If you run the process with Camunda another “hacky”- option could be to look into process instance modification and modify the process instance before ending the event-sub process from example 2. According to the BPMN standard not correct but it could work in your case.

I hope some of this is helpful  
Cheers  
Nele

---

<div class="post-metadata">

**Author:** ![singlash](https://forum.camunda.io/user_avatar/forum.camunda.io/singlash/32/12503_2.png) [@singlash](https://forum.camunda.io/u/singlash)\
**Post date:** [December 27, 2021, 6:07pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/9 "2021-12-27T18:07:59Z")

</div>

Hey Nele, thank you so much for your reply!!!

1. I want to block the main process until there’s a result in the subprocess. So parallel doesn’t really work.
2. in your test1.bpmn example, the order of message1 and message2 is corrupt.
3. for the process instance modification you mentioned, I was checking this doc [Process Instance Modification | docs.camunda.org](https://docs.camunda.org/manual/7.4/user-guide/process-engine/process-instance-modification/). It allows me to come back to the main process. But how do I know from which activity I left?  
To me, the event subprocess seems to be the best fit. But I’m not able to come back where I left. The reason I want it is because messages are only to be fired once and it will block the process if I come back in the wrong stage.  
Again, really appreciate your time!!!

---

<div class="post-metadata">

**Author:** ![Bill\_Powell](https://forum.camunda.io/user_avatar/forum.camunda.io/bill_powell/32/5502_2.png) [@Bill\_Powell](https://forum.camunda.io/u/Bill_Powell)\
**Post date:** [December 29, 2021, 6:57pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/10 "2021-12-29T18:57:54Z")

</div>

“3. how do I know from which activity I left?”

One approach would be to save the current activityId every time an activity starts into a variable through an execution listener. The history database is also capturing this, so it could be possible to retrieve/derive it from a processInstanceQuery.

---

<div class="post-metadata">

**Author:** ![Niall](https://forum.camunda.io/user_avatar/forum.camunda.io/niall/32/15333_2.png) [@Niall](https://forum.camunda.io/u/Niall)\
**Post date:** [December 30, 2021, 10:02am UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/11 "2021-12-30T10:02:51Z")

</div>

What @Bill_Powell suggested makes a lot of sense.  
i build a simple example that more or less implements that functionality, it might be useful as a reference.

> **[GitHub - NPDeehan/GenericErrorAndReturn: Showing how to throw an error...](https://github.com/NPDeehan/GenericErrorAndReturn)**
>
> Showing how to throw an error anywhere in the process and then Return back afterwards - GitHub - NPDeehan/GenericErrorAndReturn: Showing how to throw an error anywhere in the process and then Retur...

---

<div class="post-metadata">

**Author:** ![singlash](https://forum.camunda.io/user_avatar/forum.camunda.io/singlash/32/12503_2.png) [@singlash](https://forum.camunda.io/u/singlash)\
**Post date:** [January 5, 2022, 10:33pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/12 "2022-01-05T22:33:45Z")

</div>

Thanks for providing such a great sample!!!  
I was trying to use messagestart instead of errorstart in event subprocess. But after I came back to the main process, the messagestart event was no longer working while the errorstart event did work back and forth. Do you know the reason for that?

---

<div class="post-metadata">

**Author:** ![Niall](https://forum.camunda.io/user_avatar/forum.camunda.io/niall/32/15333_2.png) [@Niall](https://forum.camunda.io/u/Niall)\
**Post date:** [January 6, 2022, 8:41am UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/13 "2022-01-06T08:41:44Z")

</div>

Good question, I’m not sure about that.  
Generally speaking when a process runs the modification api on itself it can lead to strange behaviors and this could be one of those. might be worth creating a bug ticket if you think it should be working the way your intending it to.

---

<div class="post-metadata">

**Author:** ![system](https://forum.camunda.io/uploads/default/original/3X/5/8/58d50142eacca605d35cb1ef9e6b86ae85f49436.png) [@system](https://forum.camunda.io/u/system)\
**Post date:** [January 30, 2024, 1:39pm UTC](https://forum.camunda.io/t/come-back-from-eventsubprocess-to-the-main-process/32070/14 "2024-01-30T13:39:17Z")

</div>

Closed on January 30, 2024, 1:39pm UTC


