Unable to access a local variable as collection on subProcess

Hi

Referring to a model which looks like this-
image

When I am setting “values” list as process instance variable (using execution.setVariable())… everything is working good.

<process id="testCardinality" name="testCardinality" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <sequenceFlow id="sid-C89F7DBC-66E1-447C-AF67-90F99DC456FE" sourceRef="startEvent1" targetRef="sid-F14A8614-FAAC-4714-A45B-D9F28D8F0F20"></sequenceFlow>
    <scriptTask id="sid-F14A8614-FAAC-4714-A45B-D9F28D8F0F20" name="Set values" scriptFormat="groovy" flowable:autoStoreVariables="false">
      <script><![CDATA[def list1 = ['a', 'b', 'c'];
def list2 = new ArrayList<String>(list1);
execution.setVariable("values", list2);]]></script>
    </scriptTask>
    <subProcess id="sid-B246AE7F-7FBD-40C6-8E4E-8C109B8B223D" name="subProcess">
      <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="values" flowable:elementVariable="value"></multiInstanceLoopCharacteristics>
      <scriptTask id="sid-334EF73A-0590-45EA-9E24-B0AC4CE16E5F" name="print value" scriptFormat="groovy" flowable:autoStoreVariables="false">
        <script><![CDATA[out.println((String)execution.getVariable("value"));]]></script>
      </scriptTask>
      <startEvent id="sid-43FA0316-FE73-4582-9A8F-7F8AC19D3882"></startEvent>
      <endEvent id="sid-AFF9364B-39E4-4D37-A1C8-44822CCA18EB"></endEvent>
      <sequenceFlow id="sid-DCD5096A-ABD8-422C-9BDE-81EF6C5DECEA" sourceRef="sid-43FA0316-FE73-4582-9A8F-7F8AC19D3882" targetRef="sid-334EF73A-0590-45EA-9E24-B0AC4CE16E5F"></sequenceFlow>
      <sequenceFlow id="sid-FB2CE5E8-7229-4686-AE13-B20D0DFEF7C8" sourceRef="sid-334EF73A-0590-45EA-9E24-B0AC4CE16E5F" targetRef="sid-AFF9364B-39E4-4D37-A1C8-44822CCA18EB"></sequenceFlow>
    </subProcess>
    <sequenceFlow id="sid-FFDED3A8-CC67-41EB-9C30-B78293F46B66" sourceRef="sid-F14A8614-FAAC-4714-A45B-D9F28D8F0F20" targetRef="sid-B246AE7F-7FBD-40C6-8E4E-8C109B8B223D"></sequenceFlow>
    <endEvent id="sid-161F4960-267C-4811-AFD9-4F03B096A008"></endEvent>
    <sequenceFlow id="sid-368ED978-3469-4022-BE0E-55A2A9194EBE" sourceRef="sid-B246AE7F-7FBD-40C6-8E4E-8C109B8B223D" targetRef="sid-161F4960-267C-4811-AFD9-4F03B096A008"></sequenceFlow>
  </process>

But, while setting “values” list as local variable (using execution.setVariableLocal())… I am getting this error.
org.flowable.common.engine.api.FlowableIllegalArgumentException: Variable ‘values’ was not found

<process id="testCardinality" name="testCardinality" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <sequenceFlow id="sid-C89F7DBC-66E1-447C-AF67-90F99DC456FE" sourceRef="startEvent1" targetRef="sid-F14A8614-FAAC-4714-A45B-D9F28D8F0F20"></sequenceFlow>
    <scriptTask id="sid-F14A8614-FAAC-4714-A45B-D9F28D8F0F20" name="Set values" scriptFormat="groovy" flowable:autoStoreVariables="false">
      <script><![CDATA[def list1 = ['a', 'b', 'c'];
def list2 = new ArrayList<String>(list1);
execution.setVariableLocal("values", list2);]]></script>
    </scriptTask>
    <subProcess id="sid-B246AE7F-7FBD-40C6-8E4E-8C109B8B223D" name="subProcess">
      <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="values" flowable:elementVariable="value"></multiInstanceLoopCharacteristics>
      <scriptTask id="sid-334EF73A-0590-45EA-9E24-B0AC4CE16E5F" name="print value" scriptFormat="groovy" flowable:autoStoreVariables="false">
        <script><![CDATA[out.println((String)execution.getVariable("value"));]]></script>
      </scriptTask>
      <startEvent id="sid-43FA0316-FE73-4582-9A8F-7F8AC19D3882"></startEvent>
      <endEvent id="sid-AFF9364B-39E4-4D37-A1C8-44822CCA18EB"></endEvent>
      <sequenceFlow id="sid-DCD5096A-ABD8-422C-9BDE-81EF6C5DECEA" sourceRef="sid-43FA0316-FE73-4582-9A8F-7F8AC19D3882" targetRef="sid-334EF73A-0590-45EA-9E24-B0AC4CE16E5F"></sequenceFlow>
      <sequenceFlow id="sid-FB2CE5E8-7229-4686-AE13-B20D0DFEF7C8" sourceRef="sid-334EF73A-0590-45EA-9E24-B0AC4CE16E5F" targetRef="sid-AFF9364B-39E4-4D37-A1C8-44822CCA18EB"></sequenceFlow>
    </subProcess>
    <sequenceFlow id="sid-FFDED3A8-CC67-41EB-9C30-B78293F46B66" sourceRef="sid-F14A8614-FAAC-4714-A45B-D9F28D8F0F20" targetRef="sid-B246AE7F-7FBD-40C6-8E4E-8C109B8B223D"></sequenceFlow>
    <endEvent id="sid-161F4960-267C-4811-AFD9-4F03B096A008"></endEvent>
    <sequenceFlow id="sid-368ED978-3469-4022-BE0E-55A2A9194EBE" sourceRef="sid-B246AE7F-7FBD-40C6-8E4E-8C109B8B223D" targetRef="sid-161F4960-267C-4811-AFD9-4F03B096A008"></sequenceFlow>
  </process>

Why can’t this subprocess read local variable, am I missing something?

Hey,

When you do execution.setLocalVariables then the variables are set locally in the execution, i.e. the “Set Values” Script Task, and not on the process instances level. Doing execution.setVariable will actually set the variable to the first scope (process instance). Therefore the sub process can access them.

Cheers,
Filip

Hi filiphr

When I create a simple model using two script taks, like:-
image
Here I am able to access the value on 2nd script task.

Why is this case different than the one mentioned above?