cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly start a new process from inside a service task ?

guillaume1
Champ on-the-rise
Champ on-the-rise
Hello,

I have created a custom palette element following the user guide about this topic.

This new activity is in fact a 'configuration mask' for a CallActivity with a complex input map.

So the execute method of the JavaDelegate that is called by this custom palette element at runtime is like this:

<java>
@Override public void execute(DelegateExecution execution) throws Exception {
   // prepare the variables from the execution

    runtimeService.startProcessInstanceByKey("ProcessToStart", execution.getVariables());
  }
<java>

It works, but then I have a problem with historical queries:
processes started with way don't have any parentId.

So my questions:
- Is it the right way to do? Should I change the type of the javaDelegateClass used in my custom component ? If not what should I use ?
- If it is the right way, how should I start the sub process in order to have a parent defined to it ?
12 REPLIES 12

pmsevestre
Champ in-the-making
Champ in-the-making
If you want the started process to appear as a child I think you must use a "call activity" element in the parent process.

Since the process name can be an EL, you can dynamically determine which process to start based on your specific requirements.

guillaume1
Champ on-the-rise
Champ on-the-rise
I don't know how to start a CallActivity when using custom palette element.
The documentation about this topic says that you have to use a JavaDelegate class and the XML generated by the custom element is a ServiceTask.

In fact, as said in my message, the custom palette element is a 'configuration mask' for a CallActivity with a complex input map.
We have some core processes that have a complex input map with mandatory/optionnal field. Having a custom palette element allow an easier integration of these processes: they have a specific Icon, and more important a custom form to set the input.

jbarrez
Star Contributor
Star Contributor
> I don't know how to start a CallActivity when using custom palette element.

You would need to extend the CallActivityBehavior, or at least inspire yourself by the code there.

guillaume1
Champ on-the-rise
Champ on-the-rise
Ok, I'll try that. So we can re-use any activiti Behavior as a custom palette element delegate ?

guillaume1
Champ on-the-rise
Champ on-the-rise
So it works, but now I have this error when the called sub-process terminates:
<java>
java.lang.ClassCastException: org.activiti.engine.impl.bpmn.helper.ClassDelegate cannot be cast to org.activiti.engine.impl.pvm.delegate.SubProcessActivityBehavior
at org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessEnd.eventNotificationsCompleted(AtomicOperationProcessEnd.java:49)
</java>

In the AtomicOperationProcessEnd#eventNotificationsCompleted method the activity behavior is a ClassDelegate, and this last does not implements the SubProcessActivityBehavior.

in the eventNotificationCompleted(), around line 49
<java>

subProcessActivityBehavior = (SubProcessActivityBehavior) activity.getActivityBehavior();

</java>
debugger view:
<code>
activity = {org.activiti.engine.impl.pvm.process.ActivityImpl@6664}"Activity(test)"
activities = {java.util.ArrayList@6676} size = 0
activityBehavior = {org.activiti.engine.impl.bpmn.helper.ClassDelegate@6102}
  activityBehaviorInstance = {my.palette.Test@6084}
  bpmnActivityBehavior = {org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior@6706}
  className = {java.lang.String@6703}"my.palette.Test"
  executionListenerInstance = null
  fieldDeclarations = {java.util.ArrayList@6704} size = 6
  multiInstanceActivityBehavior = null
  taskListenerInstance = null
</code>

Any idea about how to fix this? (I'm using activiti 5.14, so maybe it is a fixed bug)

jbarrez
Star Contributor
Star Contributor
Hmm seens like you've hit a bug here in the core engine Smiley Sad

The fix is easy, I've done it already on master: https://github.com/Activiti/Activiti/commit/92262ae31fda26a153e16b1fe5e4eed5c1fa9903

There is a workaround, but it's pretty complex: you can replace the default Classdelegate with one that has the fix in the commit above. The ActivityBehavipourFactory is responsible for creating it, and you can plugin in your own version of it.

guillaume1
Champ on-the-rise
Champ on-the-rise
Thank you very much for solving the bug so quickly and for your help about this topic.
I'll try to put the workaround in place in our current version in order to use the custom palette.



By the way I always got a nasty error message from eclipse that complains about the custom palette jar I have created:
"There was an error when processing an extension to Activiti Designer. The extension at location x/y/z.jar is not open. Please make sure it is not installed inside the Eclipse workspace."

Custom elements are not displayed, and processes containing those element are not loaded too !

However If I open a blank diagram (either a new or a saved one) in a new project, then the palette is loaded and I can use it with my other projects and open processes definition that contains those custom activity.
So I'm still not confident about the custom palette: I fear that for some reason the work around won't work anymore and that will prevent me to open any of the processes that will use the palette.

I found that some other people had the same issue, but I did not find any real fix. Do you have any idea about this ?

jbarrez
Star Contributor
Star Contributor
Hmmm could it be the old process was made with a palette that now "doesn't exist" anymore? Or do you also see it when the palette hasn't changed yet.

The workaround shouldn't have influence, cause it's on the engine (runtime - execution) level where the fix is.

guillaume1
Champ on-the-rise
Champ on-the-rise
I always had the issue with my eclipse version (Eclipse SDK Version: 4.2.2 Build id: M20130204-1200) and the 5.14 designer.
I don't think it is related to the workaround, I think something is wrong with eclipse…