cancel
Showing results for 
Search instead for 
Did you mean: 

Element Variable not being assigned to subprocess for MultiInstanceLoop

jorell
Champ in-the-making
Champ in-the-making
I seem to be having a very basic problem. I have the following node in a parent process:


<callActivity id="createSubs" name="CreatSubs" activiti:exclusive="false" calledElement="multiInstanceLoopSub">
      <extensionElements>
        <activiti:in source="line_item_id" target="l_i_id"/>
        <activiti:out source="o_id" target="order_id"/>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="c_ids" activiti:elementVariable="creative_id"/>
    </callActivity>


I set c_ids to be an ArrayList having values a,b,c. I have a custom type for list and that is the type of the variable 'c_ids'. I do see three subprocesses instantiated but none of them have a creative_id variable. When I look in the db I see this:

select * from ACT_RU_VARIABLE where NAME_='creative_id';

+——-+——+——–+————-+—————+—————+———-+—————+———+——-+——-+——–+
| ID_   | REV_ | TYPE_  | NAME_       | EXECUTION_ID_ | PROC_INST_ID_ | TASK_ID_ | BYTEARRAY_ID_ | DOUBLE_ | LONG_ | TEXT_ | TEXT2_ |
+——-+——+——–+————-+—————+—————+———-+—————+———+——-+——-+——–+
| 10087 |    1 | string | creative_id | 10083         | 10072         | NULL     | NULL          |    NULL |  NULL | a     | NULL   |
| 10093 |    1 | string | creative_id | 10084         | 10072         | NULL     | NULL          |    NULL |  NULL | b     | NULL   |
| 10100 |    1 | string | creative_id | 10085         | 10072         | NULL     | NULL          |    NULL |  NULL | c     | NULL   |


Now 10072 is the process id of the PARENT process not the sub process (which in this case is 10088). In the sub process in the first task I have a delegate and in that delegate execution.hasVariable("creative_id") returns null. So I'm confused why the variables were created in the parent process and not in the child process. And how I am supposed to accessing them in the subprocess delegate without traversing the execution chain to the parent.
8 REPLIES 8

jbarrez
Star Contributor
Star Contributor
A call activity is actually not one execution in the db, but at least two. The element variable is set on the topmost, so it can be found in all the children.

I'm assuming you have an error with this? What doesn't work in this setup?

jorell
Champ in-the-making
Champ in-the-making
There isn't an error as such. I just cant access the "creative_id" variable in the subprocess delegates. I have this snippet in the first task of the multiInstanceLoopSub process:

<code>
<serviceTask id="taskId" name="Task Name" activiti:class="com.xyz.delegatename" >
      <extensionElements>
       <activiti:field name="variableNames">
          <activiti:string>
            creative_id,
            l_i_id,
            o_id
          </activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>
</code>
The creative_id in the delegate is not there. When I do execution.hasVariable("creative_id") I get back false.

jbarrez
Star Contributor
Star Contributor
Okay, I would need your whole process (as simplified as much as possible, but still showing the error) so I can verify it and fix it in the engine if it is a bug. Would that be feasable.

jorell
Champ in-the-making
Champ in-the-making
Here is the parent process:

<code>
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
             targetNamespace="testMultiInstanceLoop"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn">

  <process id="multiInstanceLoop" name="Test MultiInstance Loop Process" >

    <!– nodes –>
    <!– Start Node –>
    <startEvent id="start" name="Start" >
      <extensionElements>
        <activiti:formProperty id="creative_ids" name="creative_ids" type="list" required="true"/>
        <activiti:formProperty id="line_item_id" name="line_item_id" type="string" required="true"/>
      </extensionElements>
    </startEvent>

    <!– Sample Tasks –>   
    <callActivity id="createSubs" name="createSubs" activiti:exclusive="false" calledElement="multiInstanceLoopSub">
      <extensionElements>
        <activiti:in source="line_item_id" target="l_i_id"/>
        <activitiSmiley Surprisedut source="o_id" target="order_id"/>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="false" activiti:collection="c_ids" activiti:elementVariable="creative_id"/>
    </callActivity>
   
    <serviceTask id="verifyResult" name="Verify Result" activiti:class="com.xyz.somedelegatename" >
      <extensionElements>
       <activiti:field name="variableNames">
          <activiti:string>
            createSubs_order_id_map
          </activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>

    <!– End Node –>
    <endEvent id="end" name="End" />

    <!– connections –>
    <sequenceFlow id="flow1" sourceRef="start" targetRef="createSubs" />
    <sequenceFlow id="flow2" sourceRef="createSubs" targetRef="verifyResult" />
    <sequenceFlow id="flow3" sourceRef="verifyResult" targetRef="end" />
  </process>
</definitions>
</code>

Here is the child:

<code>
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
             targetNamespace="testMultiInstanceLoop"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn">

  <process id="multiInstanceLoopSub" name="Test MultiInstance Loop Sub Process" >

    <!– nodes –>
    <!– Start Node –>
    <startEvent id="start" name="Start" >
      <extensionElements>
        <activiti:formProperty id="creative_id" name="creativeId" type="string" required="true"/>
        <activiti:formProperty id="l_i_id" name="lineItemId" type="string" required="true"/>
      </extensionElements>
    </startEvent>

    <!– Sample Tasks –>   
    <serviceTask id="taskId" name="Task Name" activiti:class="com.xyz.delegatename" >
      <extensionElements>
       <activiti:field name="variableNames">
          <activiti:string>
            creative_id,
            l_i_id,
            o_id
          </activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>

    <!– End Node –>
    <endEvent id="end" name="End" />

    <!– connections –>
    <sequenceFlow id="flow1" sourceRef="start" targetRef="taskId" />
    <sequenceFlow id="flow3" sourceRef="taskId" targetRef="end" />
  </process>
</definitions>
</code>

To summarize, I am unable to access 'creative_id' in com.xyz.delegatename using execution.hasVariable() method. Please let me know if I can provide more info.

trademak
Star Contributor
Star Contributor
That's because creative_id is not passed as a variable to the sub process. What you could do is define a multi-instance sub process and then have a call activity in there that also provides create_id as one of the input parameters (with an activiti:in element).

Best regards,

jorell
Champ in-the-making
Champ in-the-making
I would be surprised if I need to explicitly pass in creative_id to the sub process. When I have a multiInstance Loop like below:

<code>
<multiInstanceLoopCharacteristics isSequential="false" activiti:collection="c_ids" activiti:elementVariable="creative_id"/>
</code>

The activiti:elementVariable is supposed to do exactly that, according to the documentation:

<code>
Suppose the variable assigneeList contains the values [kermit, gonzo, foziee]. In the snippet above, three user tasks will be created in parallel. Each of the executions will have a process variable named assignee containing one value of the collection, which is used to assign the user task in this example.

The downside of the loopDataInputRef and inputDataItem is that 1) the names are pretty hard to remember and 2) due to the BPMN 2.0 schema restrictions they can't contain expressions. Activiti solves this by offering the collection and elementVariable attributes on the multiInstanceCharacteristics:
</code>

Otherwise in my case where I have a multiInstance loop inside a call activity, I see no point in using activiti:elementVariable. Please let me know if I misunderstood.

trademak
Star Contributor
Star Contributor
No that's not correct. You have to pass every variable you want to set in the sub process context via input parameters of a call activity. Nothing is passed automatically, so also not the multi instance element variable. The element variable is only available in the parent process context.

Best regards,

jorell
Champ in-the-making
Champ in-the-making
Alright. I understand that that's how its coded right now. But what is the justification to keep it this way. When a user uses the elementVariable attribute in a multiInstance loop, it is clear the intent is to use this variable in the subprocess. Why not provide this to the subprocess implicitly without having them explicitly provide it?
Thanks for taking the time to look at this Tijs.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.