cancel
Showing results for 
Search instead for 
Did you mean: 

subprocess definition in a separate xml

taurus
Champ in-the-making
Champ in-the-making
Hello,

Is it possible to have a subprocess definition in a separate BPMN xml file so that this subprocess could be used by several application modules? I was searching for some 'include' tag in the BPMN xml, but didn't find anything.

Thanks!
10 REPLIES 10

trademak
Star Contributor
Star Contributor
Hi,

Sure. You can define a sub process in a separate process definition and invoke it from a call activity.
Note that this sub process can also be started as a main process definition as it's just a normal process definition.

Best regards,

taurus
Champ in-the-making
Champ in-the-making
Thanks for the quick answer!
Could you please share some xml examples or give some url to follow?

trademak
Star Contributor
Star Contributor
This is explained very well in the userguide. And in the Activiti download you can find all kind of process examples in the workspace directory.

Best regards,

Hello,
"And in the Activiti download you can find all kind of process examples in the workplace directory", you said
where are they ? can you provide a link ?

mhw
Champ in-the-making
Champ in-the-making
Hi taurus,

I have an example for you:
Main process (in file: Example_Spec_02_calling_process.bpmn20.xml):
<process id="callingProcess" name="Process with call activity">
  <startEvent id="theStart" />
  <sequenceFlow id="flow1" sourceRef="theStart" targetRef="startIgnition" />
  <manualTask id="startIgnition" name="Start ignition manutally" />
  <sequenceFlow id="flow2" sourceRef="startIgnition"
   targetRef="subProcess" />
  <callActivity id="subProcess" name="Check ignition status"
   calledElement="externalSubProcess" />
  <sequenceFlow id="flow3" sourceRef="subProcess"
   targetRef="measureVoltageTask" />
  <userTask id="measureVoltageTask" name="Measure voltage" />
  <sequenceFlow id="flow4" sourceRef="measureVoltageTask"
   targetRef="theEnd" />
  <endEvent id="theEnd" />
</process>
Subprocess(in file: Example_Spec_02_sub_process.bpmn20.xml):
<process id="externalSubProcess">

  <startEvent id="theStart" />
  <sequenceFlow id="flow1" sourceRef="theStart"
   targetRef="verifyIgnitionOn" />

  <userTask id="verifyIgnitionOn" name="Verify ignition on." />
  <sequenceFlow id="flow2" sourceRef="verifyIgnitionOn"
   targetRef="confirmIgnitionOn" />

  <exclusiveGateway id="confirmIgnitionOn" />
  <sequenceFlow id="flow3" sourceRef="confirmIgnitionOn"
   targetRef="feedbackTask">
   <conditionExpression><![CDATA[${!ignitionOn}]]></conditionExpression>
  </sequenceFlow>
  <sequenceFlow id="flow4" sourceRef="confirmIgnitionOn"
   targetRef="normalEnd">
   <conditionExpression><![CDATA[${ignitionOn}]]></conditionExpression>
  </sequenceFlow>

  <userTask id="feedbackTask" name="Ignition not activated." />
  <sequenceFlow id="flow5" sourceRef="feedbackTask"
   targetRef="endEvent" />
  <endEvent id="endEvent" />

  <endEvent id="normalEnd" />

</process>

My test method:
@Deployment(resources = {
   "com/bigfirm/wfe/test/res/Example_Spec_02_calling_process.bpmn20.xml",
   "com/bigfirm/wfe/test/res/Example_Spec_02_sub_process.bpmn20.xml" })
public void testSpec02SubProcess() throws Exception {
  // After the process has started, the 'Start ignition' task
  // should be active
  ProcessInstance pi = runtimeService
    .startProcessInstanceByKey("callingProcess");
  TaskQuery taskQuery = taskService.createTaskQuery();
  Task startIgnition = taskQuery.singleResult();
  assertEquals("Verify ignition on.", startIgnition.getName());

  // Verify with Query API
  ProcessInstance subProcessInstance = runtimeService
    .createProcessInstanceQuery()
    .superProcessInstanceId(pi.getId()).singleResult();
  assertNotNull(subProcessInstance);
  assertEquals(pi.getId(), runtimeService.createProcessInstanceQuery()
    .subProcessInstanceId(subProcessInstance.getId())
    .singleResult().getId());

  // Completing the task with approval, will end the subprocess and
  // continue the original process arriving at the "Measure voltage task"
  taskService.complete(startIgnition.getId(),
    CollectionUtil.singletonMap("ignitionOn", true));
  Task mesureVoltageTask = taskQuery.singleResult();
  assertEquals("Measure voltage", mesureVoltageTask.getName());
}

The important thing here is that both xml file has to be deployed.

Best regards,
Michael

ps: would be interested what example with sub process in different file I have overlooked. I have not found one in the activiti examples (which are very good and verbose - many thanks for that)

taurus
Champ in-the-making
Champ in-the-making
Thanks Michael for your helpful examples. I was successfully able to run the test.
Actually my concern was how to specify the xml filename to look for subprocess definition, but now I realize that engine looks in all xml resources.

Thank you very much again.

amir_kourani
Champ in-the-making
Champ in-the-making
I know i am very late to talk in this topic but how i can see the "called element" or subprocess in the activiti designer and activiti explorer.

jbarrez
Star Contributor
Star Contributor
eum … simply xml view or the properties window … ?

Don't quite get what you are looking for.

hansbak
Champ in-the-making
Champ in-the-making
I am even later in the process. Here  an absolute beginner…want to use the eclipse designer to map our company in levels of detail, so i try to use the callActivity

I am trying with Eclipse Luna (4.4.1) and the activiti plugin 5.15 and entered the above examples from MHW
The diagrams show fine, however i see no way of going from the calling process and then want to go to the subprocess. When i try to link the calling process to the subprocess the window is empty for selection.

It also says: The important thing here is that both xml file has to be deployed.

can i do that in the eclipse pugin? i did not see any option anywhere…..

your help is appreciated…

Regards,'Hans