cancel
Showing results for 
Search instead for 
Did you mean: 

Variables in a sub process

walterjs
Champ in-the-making
Champ in-the-making
I have a simple approval sub process that can have multiple instances created at a time. I want to use the result of the approval in the parent process. As soon as anybody rejects, all other instances are destroyed and the process is rejected. Basically it needs 100% approval by everybody. This all works fine, except that I have to create a service task just before the end event in the sub process with the following expression to get the variable to the parent process:
${'reject'.equals(execution.getProcessInstance().getVariable('decision')) ? execution.getId() : execution.getProcessInstance().setVariable('decision', decision)}

I only want to write the decision back to the parent if it has not been rejected already, hence the condition in the expression.

If I do not do this, the parent process knows nothing about the "decision" variable. Is there another way of getting the sub-process variables to the parent process like with a call activity?

Also, does anybody have a cleaner way of doing this expression?

Thanks
Walter
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
embedded subprocesses share the same variable context as the parent process instance, wo why do you need to set them explicitely?

walterjs
Champ in-the-making
Champ in-the-making
If I do not do this, the parent process knows nothing about the "decision" variable.

I get an "Unknown variable used in expression" exception.

embedded subprocesses share the same variable context as the parent process instance, wo why do you need to set them explicitely?

So, if this is true, I should never get the above exception and I also have to worry about concurrency when I have a multi-instance sub-process as the last sub-process to set the variable will overwrite any previous value and different sub-processes would constantly be overwriting each other's values.

Thanks
Walter

jbarrez
Star Contributor
Star Contributor
That will depend on how you configure your multi instance (sequential will try to reuse the execution).

If you can put it in a unit test, I can better understand what you are trying to do.

walterjs
Champ in-the-making
Champ in-the-making
Ah, ok. I understand your previous post now. The sub-process is not running sequentially, so therefore it will not use the parent execution.

My question really was just if there was a way to output variables from an embedded sub-process like with a call activity so that I didn't have to add the service task to set the variable. If not, I will make do with the service task.

I will submit a unit test today hopefully.

Thanks
Walter

yogesh1454
Champ in-the-making
Champ in-the-making
Hi I am unable to return a variable from the subprocess to its parent process .I am using a call activity to sequentially call a process and on rejection inside the subprocess i want to terminate the main processs