Location of activity

Hi team,

I have created subprocess which has attached error boundary event which works flawlessly on top of that I have created a form for user where people can decide in case of error whether continue in the process or start again subprocess. The problem is that I cannot locate the start activity inside subrpocess via createProcessInstanceModification

I have unsucessfully tried to use getChildActivityInstances.

Thanky you for any suggestions

Michal

Hi Michal,

Might be a nicer solution to just send the toke back to the subprocess which will kick off the start event of the subprocess again something like this:

Thanks for the reply.

Your idea is briliant it might work unfortunately I have realized that I have not expressed myself correctly. I am trying to find a way how to start a particular task in the “main” subprocess not whole “main” subproces as it in my case has multiple tasks (service tasks) which I don’t want to trigger again.

I am using 7.3.0, the below is my attempt without getChildActivityInstances

ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
runtimeService.createProcessInstanceModification(processInstance.getId())
.cancelActivityInstance(“Repeat_it”)
.startBeforeActivity(“Shell_sc”)
.execute();

Thank you for any suggestions.

Michal

Well i don’t think it’s a good idea to code a process instance modification into your model. It will end up making the model far more difficult to follow in run time.

The Process instance modification feature is intended to be used when someone unexpected happens in your model and intervention is required. So i would suggest you try to model the behavior explicitly rather than using Process instance modification.

Maybe you could share your model and i could see what options you might have - and if the functionality you’re looking to achieve isn’t possible i can help you more with moving the token via code.

1 Like

Sample.xml (35.1 KB)

The idea I did want to achieve was to have some kind of error management (to let a user decide where to continue from a form)
E.g. if ShellScript had a problem to run I would like to let user know that via form so a person can decide whether continue with a next task or repeat the tasks again.
Which would be applicaple for all process instances.

Thank you for any suggestions

Michal

From a best practice perspective we generally to suggest avoiding modeling those kinds of system errors - error management is best done from cockpit (or some other greater scope). There are a few reasons why we suggest this but the most obvious one is that there are so many things that could go wrong in a process it becomes impossible to keep track of all “safe guards” you might want to model.

Well I’ve thought of three ideas that are worth considering -

  1. Use a gateway.
    Instead of letting the script error - you could catch the error and set a process variable with the status of how the script went. then test it to see what should be done next. Then a sequence flow could send the user where they want to go.

  2. Use a boundary event on the scrip task
    If you catch the error on the task itself you’ll still have the context of the whole sub-process so they’ll be easier. to have a sequence flow move the token to a variety of tasks dependent on user input.

  3. Use CMMN for the processes
    CMMN has a lot more power when it comes to activating tasks based on user input and doesn’t require sequence flows. .

If you’re still interested in using the process instance migration just let me know what issue you’re having with your current approach and I’ll try and help you out.

Thank you for your reply.
there are really good points there to think about.

I would appreciate if you still can help me to use the process instance migration.

The problem I am currently experiencing is that I am not able to correctly locate a tasks which thrown an error so I can start the task error task again or the task before or after. (in my case I did model an error which happens during “ShellScript” service task)

I have tried multiple ways how to achieve this
the last code I wrote looks like this (initiated from “Repeat” service task) .
Just a note: could it be that the 7.3.0 had a bug which prevents me to run the code?
https://groups.google.com/forum/#!topic/camunda-bpm-users/RwltjvC3f8k

ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();

ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
runtimeService.createProcessInstanceModification(processInstance.getId())

//.startBeforeActivity(activityId, ancestorActivityInstanceId)
.startBeforeActivity(“Shell_sc”, activityInstanceTree.getParentActivityInstanceId())
.execute();

Michal