How to create a variable with a more restrict scope to control the flow?


Hi. My use case is that (I had to put all the information in one image because the forum says that new users can upload only one image):

I think the image is self-explanatory, but if not, this is the description: I have a list of documents that need to be uploaded by a user and reviewed by another one. In the review Task, the user should fill a boolean value that represents if the document is ok. If the document is ok, it flows to the next task; otherwise, the flow should return to the Upload task.

What I tried to do:

I created a form variable “isOk” in each of the Review tasks and a complete listener to set an execution variable based on this form variable (image above).

But I realized that the scope of the form variable is the entire process instance. That way, the second Task of the type “Review” will be initialized with the value filled in the first Task of type “Review”.

I could solve this problem by creating different variable names based on the document name (for example, isDutOk, isCnhOk etc) and eliminating the listener. But I am not happy with this solution. The problem is that as a programming best-practice, it is better to make the scope of a variable as strict as possible. Moreover, if all tasks had the same variable name, it could be much easier to copy/paste to create other ones.

Can I create a more generic variable name only in the scope of a single Task in Camunda and makes this flow works?

I am also sending my bpmn if you want to inspect it.

Thanks in advance!

poc-docs-default (copy).bpmn (10.7 KB)


Hi @Regis_Hattori,

there is a simple solution to your problem. Just add another Listener to your review task that deletes this variable.

For example you can add a new ExecutionListener with the following properties:

Event Type: start
Listener Type: Script
Script Format: JavaScript
Script Type: Inline Script
Script: execution.removeVariable(“isOk”);

You can also just write this code as an Expression if you prefer it this way.

Hope that helps.



Hi @Regis_Hattori

as this is correct for programming I would not take too serious for workflow automation. Each step has to add some value that is needed in one of the next step. So it is normal to add (or change) a variable in each activity.

Scoping can be done with the help of embedded subprocesses ( or call activities (

Cheers, Ingo