cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a dynamic step while the instance is in flight

dilipl1
Champ in-the-making
Champ in-the-making
I have been evaluating Activitii to see if it helps us achieve what we are trying to accomplish.

Essentially we want the ability to add a dynamic step (available to be picked up from a list of steps) at any point in the process thereby affecting the instance in flight. The step can be added anywhere in the flow, obviously where the instance hasn't been to yet. So for example if I am at step 2 below, I should be able to add a step anywhere after step 2.

step 1 –> step 2 –> step 3 –> step 4

The original process should not be modified, just the one affecting the current instance.

I did see, that I can dynamically pick a subprocess (at runtime), however we want to be able to add a step anywhere. Any feedback is appreciated…thanks
12 REPLIES 12

dilipl1
Champ in-the-making
Champ in-the-making
Like, illustrated in this blog. Is this possible with activiti 5.9? Really appreciate if the stalwarts here respond. We are trying to see if we need to build our own workflow engine or if activiti will satisfy this crucial requirement.

http://mauricedechateau.blogspot.com/2010/07/adding-task-nodes-dynamically-at.html

Mainly we want to add a dynamic step (out of a step library) at any point of the process for the current instance. This will happen not too often in production but is a crucial requirement.

Thank you guys.

croc1
Champ in-the-making
Champ in-the-making
I want to ask this question too!

meyerd
Champ on-the-rise
Champ on-the-rise
Hi dilipl and croc,

Consider that the process definition is static and we literally reuse the same instance of a process definition object for each instance at runtime (see DeploymentCache). 
So if you modify the PD, the modification will be propagated to *all* running instances in that process engine instance.

What you can already do is, if you have a UserTask, you can add dynamic subtasks at runtime. These will be properly linked  to the given "parent" task in the process definition.

Other than that what you could do is add a set of tasks to the process definition which are not related to the "main" flow of the process (have no incoming / outgoing sequence flows, and then in a custom ActivityBehavior you set the execution to one of these tasks and continue there.
So that would look somewhat like this: (warning: untested pseudo-code):


String dynamicActivityId = "myDynamiyAct";
ActivityImpl dynamicActivity = processDefinition.findActivityById(dynamicActivityID);
execution.setActivity(dynamicActivity);
AtomicOperation.ACTIVITY_START.execute(execution);

This will get you to the activity. Note that if the activiti is a scope, this will not create a new scope execution. Also in other respects, it is a very dirty hack.

So I guess It is always possible to do something like this, but you have to weigh whether you are willing to pay the price. I would advise against, in most cases.

dilipl1
Champ in-the-making
Champ in-the-making
Thanks for your response meyerd.

I am going to try both these approaches and do a demo and see if this works. Here's a couple of questions

1) The subtask approach
   a) When a subtask is added under an already present task (usertask or servicetask correct?) at runtime, I will need a spring bean associated with it (java delegate). The user will only be able to pick from a fixed set of tasks (to make it  a subtask). Is this possible? Can I have some a spring bean associated with a dynamic subtask?

2) Disconnected tasks present in the process
With the second approach, I don't like all the tasks just sitting in the process either, but I can see where I can have a spring bean associated with it since the task will be present in the process.

I like approach 1 as it eliminates the litter, but can I associate a spring bean with a dynamic subtask?

Thanks so much

dilipl1
Champ in-the-making
Champ in-the-making
Hey everyone and meyerd,

I am trying to do what you indicated in strategy 2 above since subtasks don't work. So, say I am at step 1 in my current execution and I want to add step 3.5.

step 1 –> step 2 –> step 3 –>step 3.5–> step 4

I do not want to go to step 3.5 yet. I just want to add it. I am at step 1 right now
ActivityImpl dynamicActivity = processDefinition.findActivityById("step3.5");

Now how do I change transitions from 3 to 3.5 and 3.5 to 4 instead of 3 to 4??

All help is appreciated

nemesis1
Champ in-the-making
Champ in-the-making
Hi,

I want to add another question. I draw a process which has seperate tasks (no incoming, no outgoing sequence flows), some task collections so that I can visualize my questions.

Is it possible

-when I am in user task 2 in main process, can I go to another task except main process. (for example user task 6 or collection 1) After I complete this task can I return to main process to complete remaining process.
-Is it possible to form process fragments as collection 1 or collection2. If it is possible, can I return to main process. (I see an example on drools and they call it as ad-hoc.)
-If I can form collections, is it necessary to put end event or start event.
-Maybe it should be the main question. Does activity designer support seperate tasks in process.

Our main aim is to supply flexibility to users. In another topic, I asked you when noninterrupting and interrupting  boundary event will be supported. I think  this wil also supply flexibility to users.

Thanks.

dilipl1
Champ in-the-making
Champ in-the-making
Hey Activiti gurus,

Can someone please chime in to my question and then nemesis'

Here is some code, that helps me get an instance and then the process definition. I then get the activity (task). However I do not know the right way to change transitions to add step3.5 from my post above.

step 1 –> step 2 –> step 3 –>step 3.5–> step 4


ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
ProcessDefinitionEntity pd = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery()
    .processDefinitionId(processInstance.getProcessDefinitionId()).singleResult();
ActivityImpl dynamicActivity = pd.findActivity("step3.5");
ActivityImpl afterActivity = pd.findActivity("step3");

Thank you and appreciate all your inputs. If I can do this, it will help me sell activiti to my team.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
when modifyin the definition, it is for all instances…!!!

why not add dynamic 'subprocesses'  at the places where you want some dynamic things to take place? what 'subprocess' will be executed can be decided runtime. that can eithe be some predefined and deployed ones, or even one you create runtime.

dilipl1
Champ in-the-making
Champ in-the-making
Hey Ronald,

I actually checked out the functionality (there is even a test in activiti examples) to pick a subprocess at runtime.
However what we (and many others) want is the capability to add a task at any point and not at a predefined spot. I will give you an example.

Consider my diagram with steps 1 thru 4 above and my current execution is on step 1.  Now a plant engineer, for just one work-order (instance) wants to go in and add a step 3.5. Just as likely, they could have added step 2.5. So I can't have subrocesses called at predefined steps.

What do you think Ronald? Any way to accomplish this?