cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically add an instance to Multi-instance?

cgarci
Champ in-the-making
Champ in-the-making
Hello,

I am new to activiti so please excuse me if what I am asking is to basic but I couldn't find any proper answer for it in the forum. Thanks!

Scenario

I have to implement a workflow to review different files/attachments that a PM uploads to a repository.
This revision process for each of those files will consist in 5 different steps. (subprocess)
The file revisions are independent.
While there are still some files left to be reviewed, the PM can upload new files.
When a new file is uploaded, a new revision process for that file must be started … and joined to the N previously uploaded files with an on-going revision.
Once all the files are marked as review, the process is finished.

Pseudo-Schema:

Start revision (human activity) -> Review files (n independent sub-processes) -> Close revision (human activity/service call, whatever)

… but the number of files (n) might evolve during the review process (it is not known in advance).

What does activiti offer?

I have read this on the documentation about Multi-instances:

"The number of instances are calculated once, when entering the activity"

So if this is true, my hands are laced, aren't they?

Question

Is there are way to dynamically add a new "instance" to a currently "started" multi-instance activity?

If so, could you please explain me how?

Thanks a lot in advance,

Carlos
4 REPLIES 4

pmsevestre
Champ in-the-making
Champ in-the-making
I think that the first question you should ask yourself is: what is my process instance ? Is the review process as a whole or a single file under review ? In the former case, I'd just use attachments and process variables to keep track of them.

OTOH, if the review process of a single file is something more complicated, then one possibility is to create an independent (ie, not a sub-process) review process for those where that includes a reference to the main review process. You can then use messages sent from the file review process to the main review to keep track of the overall progress.

If you're building your own UI, those different approaches can be implemented in a way that the user is mostly unaware of.

cgarci
Champ in-the-making
Champ in-the-making
Thanks for your answer, pmsevestre!

After reading your piece of advice, I think I will go for the second option: create an independent review process and keep track of the overall progress.

Regards

qswtyn
Champ in-the-making
Champ in-the-making
hi pmsevestre,
    i have same question,
if the review process of a single file is something more complicated, then one possibility is to create an independent (ie, not a sub-process) review process for those where that includes a reference to the main review process. You can then use messages sent from the file review process to the main review to keep track of the overall progress.

how to reference to the main review process? how send message to the main review process
can you point some references or something that explain what you mean?

best regards

frederikherema1
Star Contributor
Star Contributor
When starting the new process (probably from some kind of listener/service-task), add the parent-process/execution ID as a variable. Later on, in the child-process, you can use the variable to get hold of the parent process, using the EngineServices to access the API from a JavaDelegate or *Listener, using our API to send a message, set a variable or signal as usual.