# Very Imp : How to persist variables in case of Service Task Exception

**URL:** <https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145>\
**Category:** Uncategorized\
**Created:** [June 20, 2018, 9:43am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145 "2018-06-20T09:43:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arpit.agrawal](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@arpit.agrawal](https://forum.flowable.org/u/arpit.agrawal)\
**Post date:** [June 20, 2018, 9:43am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/1 "2018-06-20T09:43:00Z")

</div>

Hi,

Can someone plz reply ASAP if there is a way to persist variables set using execution.setVariables in case service task throws an exception.  
The use case is 4 service tasks in a row. 4th task throws an exception. Process rolls back to last user task (deleting success response from 1st 3 service tasks). Now when user re-submits, first 3 service tasks are again called. Problem is we can call one of the first 3 services only once after success is returned, after that it will send us error response and if we receive error we throw exceptions from service task. Now user is stuck because we are getting error response from that service and user cannot move forward.  
But if somehow i can persist the response in variables, i can use that to re run the logic and not hit the api and user can just move forward.

Thank you,  
Arpit

---

<div class="post-metadata">

**Author:** ![bdot](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@bdot](https://forum.flowable.org/u/bdot)\
**Post date:** [June 21, 2018, 10:19am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/2 "2018-06-21T10:19:21Z")

</div>

We have similar need to solve in near future, we think this is something we can achieve using event handlers.

Probably by having a customer event listener that extednds AbstractFlowableEngineEventListener which seem to have getExecution() method?

---

<div class="post-metadata">

**Author:** ![maudrid](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@maudrid](https://forum.flowable.org/u/maudrid)\
**Post date:** [June 25, 2018, 8:25am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/3 "2018-06-25T08:25:02Z")

</div>

Depending on your requirement, you can mark your service tasks as asynchronous.  
This will commit the transaction, so that if you get an exception, it will not roll back.  
In this case you need to handle the exception case so that your process does not stall.

Or you can do compensation. Have a look at the documentation.  
Using this you can cause the other service tasks to roll back in a controlled way so that, when the user tries a second time, all the service tasks are ready to process the transaction instead of giving you an error.

---

<div class="post-metadata">

**Author:** ![jit](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jit](https://forum.flowable.org/u/jit)\
**Post date:** [January 3, 2020, 6:41am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/4 "2020-01-03T06:41:55Z")

</div>

Anyone found a solution?

---

<div class="post-metadata">

**Author:** ![kicha](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kicha](https://forum.flowable.org/u/kicha)\
**Post date:** [December 5, 2025, 9:53am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/5 "2025-12-05T09:53:09Z")

</div>

Anyone identified solution?  
We are in flowable 7.1. When we go for Async, flow is not waiting for Async task to close, but next task need input from previous task. So we are using synchronous service tasks.  
We have a chain of external Bank API calls in which few are create requests, which should not be called again for same request data.

---

<div class="post-metadata">

**Author:** ![WelschChristopher](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/welschchristopher/32/2822_2.png) [@WelschChristopher](https://forum.flowable.org/u/WelschChristopher)\
**Post date:** [December 5, 2025, 10:04am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/6 "2025-12-05T10:04:24Z")

</div>

Hey Kicha,

is your task exclusive or not? If it’s result is required for a different task, it should be exclusive.

Greetings

Christopher

---

<div class="post-metadata">

**Author:** ![kicha](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kicha](https://forum.flowable.org/u/kicha)\
**Post date:** [December 5, 2025, 1:07pm UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/7 "2025-12-05T13:07:09Z")

</div>

Exclusive true is default value for Flowable BPM service tasks. Do we need to set explicitly which makes any difference ?

PS: We are using synchronous service tasks which is getting invoked sequentially.

---

<div class="post-metadata">

**Author:** ![kicha](https://avatars.discourse-cdn.com/v4/letter/k/91b2a8/32.png) [@kicha](https://forum.flowable.org/u/kicha)\
**Post date:** [December 20, 2025, 3:17am UTC](https://forum.flowable.org/t/very-imp-how-to-persist-variables-in-case-of-service-task-exception/2145/8 "2025-12-20T03:17:30Z")

</div>

We have managed through application cache outside BPM.
