cancel
Showing results for 
Search instead for 
Did you mean: 

How a Callactiviti can access the parent process variables?

purna_cherukuri
Champ in-the-making
Champ in-the-making
Hi,

I am trying to use CallActiviti in my BPMN2.0 process.  But I found it mandatory to pass the input variables to call Activiti as it runs in a child execution. 
Is there a way to pass whole set of parent execution's variables to Callactiviti without mentioning each and every one in bpmn2.0 xml?  Or is there a way to tell Callactiviti to share the variables from it's parent execution without mentioning all the variable names in my process definition?  

We have a large set of variables to pass through, and I am finding it as a maintanence issue if we hard code the variable names in process definition.  Please suggest me on this.
22 REPLIES 22

frederikherema1
Star Contributor
Star Contributor
Where do you want to use the process-variables? If you look on how activiti handles this, indeed a child-execution is created in the process-instance. In an expression or in a JavaDelegate you have the "execution" object available. If the variable is NOT defined on the execution itself (in this case, the callActivity execution), the parent is consulted. This goes up the execution-tree until a variable is found…

So just calling execution.getVariable("myVar") from within the callActivity execution will get you the values in the process…

The reason why the IN and OUT's are there, is because of the BPMN 2.0 spec. So this will only work in the activiti-engine, and is not explicit ally part of the spec Smiley Wink

purna_cherukuri
Champ in-the-making
Champ in-the-making
Thanks for the quick reply '@frederikheremans'.

What you are saying is a real good news for me if it works in the same manner.  But it is not the case I am facing.
I have created a variable in parent execution and trying to access it from Callactiviti(child execution) and it is not working.  It is returning null in that case. 

I am using Activiti5.9.  Could you please help on this?

Thank you.

seanpualion
Champ in-the-making
Champ in-the-making
I have just joined and I hope I will learn a lot of new information here.
I admire the valuable information you offered in your article. Excellent submission very good post.Keep posting thumbs up.

purna_cherukuri
Champ in-the-making
Champ in-the-making
I have debugged the code and identified that the child execution object created for CallActivity, doesnt contain the parentId.  parentId is coming as "null".  Which is causing the issue reported.  Any help on this?

Please find my bpmn xml for reference.

<process id="AccountDetails" name="AccountDetails">
    <documentation>Place documentation for the 'AccountDetails' process here.</documentation>
    <startEvent id="startevent1" name="Start"></startEvent>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="exclusivegateway1"></sequenceFlow>
    <serviceTask id="servicetask1" name="Get Asset Allocations" activiti:class="com.cgi.msuite.bpmn.wms.portfolios.tasks.GetAssetAllocationsTask"></serviceTask>
    <sequenceFlow id="flow5" name="" sourceRef="exclusivegateway1" targetRef="servicetask1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flow.equals("AssetAlloc")}]]></conditionExpression>
    </sequenceFlow>
    <serviceTask id="servicetask2" name="Get Account Transactions" activiti:class="com.cgi.msuite.bpmn.wms.portfolios.tasks.GetAccountTransactionsTask"></serviceTask>
    <sequenceFlow id="flow3" name="" sourceRef="exclusivegateway1" targetRef="servicetask2">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flow.equals("Transactions")}]]></conditionExpression>
    </sequenceFlow>
    <serviceTask id="servicetask3" name="Get Account Positions" activiti:class="com.cgi.msuite.bpmn.wms.portfolios.tasks.GetAccountPositionsTask"></serviceTask>
    <sequenceFlow id="flow7" name="" sourceRef="exclusivegateway1" targetRef="servicetask3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flow.equals("Positions")}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow6" name="" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="servicetask2" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow8" name="" sourceRef="servicetask3" targetRef="endevent1"></sequenceFlow>
    <serviceTask id="servicetask8" name="Get Maturity Schedule" activiti:class="com.cgi.msuite.bpmn.wms.portfolios.tasks.GetAccountMaturityScheduleTask"></serviceTask>
    <sequenceFlow id="flow17" name="" sourceRef="exclusivegateway1" targetRef="servicetask8">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flow.equals("MaturitySchedule")}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow18" name="" sourceRef="servicetask8" targetRef="endevent1"></sequenceFlow>
    <callActivity id="callactivity1" name="Projected Income" calledElement="AccountProjectedIncome">
      <extensionElements>
        <activiti:in source="flow" target="flow"></activiti:in>
      </extensionElements>
    </callActivity>
    <sequenceFlow id="flow19" name="" sourceRef="exclusivegateway1" targetRef="callactivity1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flow.equals("QrtlyIncmProj")}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow20" name="" sourceRef="callactivity1" targetRef="endevent1"></sequenceFlow>
  </process>


Thank you.

frederikherema1
Star Contributor
Star Contributor
If I look into the source-code, I see the super-process is being set on the created sub-process:

org.activiti.engine.impl.pvm.runtime.ExecutionImpl:139
public PvmProcessInstance createSubProcessInstance(PvmProcessDefinition processDefinition) {
    ExecutionImpl subProcessInstance = newExecution();
   
    // manage bidirectional super-subprocess relation
    subProcessInstance.setSuperExecution(this);
    this.setSubProcessInstance(subProcessInstance);
   
    // Initialize the new execution
    subProcessInstance.setProcessDefinition((ProcessDefinitionImpl) processDefinition);
    subProcessInstance.setProcessInstance(subProcessInstance);

    return subProcessInstance;
  }

Can you debug too see if the executionEntity has that field set?

purna_cherukuri
Champ in-the-making
Champ in-the-making
Hi @frederikheremans,

I have debugged and checked.  It is not coming to the method you specified at all. 
Does it take same flow even in case of callactivity?

Thank you.

frederikherema1
Star Contributor
Star Contributor
Sorry, might have been the "ExecutionEntity" instead of Impl…

purna_cherukuri
Champ in-the-making
Champ in-the-making
Yes, It is setting the superProcess details when creating the sub process instance.  But as part of executing the getVariable method, it is looking for parentId which is null.  So the it is returning parentScope as null in getVariable method.

Ideally superExecutionId is getting set properly but not parentId.

purna_cherukuri
Champ in-the-making
Champ in-the-making
Somebody please reply on this, as this is very critical to complete my evaluation of different BPMN solutions.