AnsweredAssumed Answered

Multi instance process variable scope

Question asked by mczul on Aug 7, 2014
Hi,

I'm currently working on a process definition with two layers of subprocesses that are both declared as "multi instance" and "isSequential=false".

A sample unit test can be found here: https://github.com/mczul/activiti-testcase-01

### Some background information about the business logic ###
=> Companies are associated with offers
=> One company may be associated with one or more offers
=> Offers may be outdated (which means "invalid")
=> Only employees of the associated company may know if an offer is outdated
=> Valid email addresses are available for all employees
=> Employees of a company do not have any kind of user account
=> Employees of a company must to be able to interact with the system (to validate offers)
The basic idea is to generate something like one-time "access keys" as usual when validating email addresses after creating a user account. Theses "access keys" are then used as the user-id in Activiti's identity management system. For every offer that has to be validated, a human task is created and assigned to that "access key"-user. Employees will then receive a mail with a link that contains the "access key". The page referenced by that link will finally list all relevant offers so that the employee is able to decide whether an entry is still valid or not. After completion of the validation process, the "access key"-user should be deleted.

### About the problem ###
The main process starts subprocesses for each company as expected. "Subsubprocesses" (which are responsible for the validation of single offers) are then created and executed in order to validate every offer.  Until this point everything works as expected. But when the user task completes (by user interaction or escalation), all parent subprocesses continue with the last "currentUser" process variable and not (as intended) with the "currentUser" instance created at the beginning:
=> Main process starts
=> First subprocess starts
=> First subprocess creates "access key"-user and assignes that instance to the process variable "currentUser"
=> First subprocess starts "subsubprocesses" for the validation of every offer of the first company
=> "Subsubprocesses" of the first subprocess contain user tasks assigned to "currentUser.getId()"
=> Second subprocess starts
=> Second subprocess creates "access key"-user and assignes that instance to the process variable "currentUser"
=> Second subprocess starts "subsubprocesses" for the validation of every offer of the second company
=> "Subsubprocesses" of the second subprocess contain user tasks assigned to "currentUser.getId()"
=> All user tasks of the first subprocess complete
=> First subprocess continues with "currentUser" equal to the one created by the second subprocess

Even if it would be possible for me to separate these two subprocesses: Is there any way to realize this kind of scenario?

Many thanks in advance!
Christoph

Outcomes