cancel
Showing results for 
Search instead for 
Did you mean: 

How to read element variable from multi-instance sub-process?

bobloveactiviti
Champ in-the-making
Champ in-the-making
Hallo:
How to read element variable from multi-instance sub-process? For example, I add a collection of 3 elements to the sub-process and start the process. I wish to get corresponding the element variable for each of the 3 sub-process instances in order to get a mapping between element and sub-process instance.
I could read element variable from tasks(usertask, servicetask).
Thanks in advance!
3 REPLIES 3

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Variable should be accessible in the subprocess. (elementVariable :http://www.activiti.org/userguide/#bpmnMultiInstance)
If not please create jUnit test for it.
Regards
Martin

Hi Martin,
Thanks for the reply!
The bpmn file is attached and the unit test is as below. I assign a collection of 3 variable to the  multi-instance sub-process and assert the 3 sub-process instances are running correctly. Then I wish to get element variable with predefined variable name for each of the sub-process instance using activitiRule.getRuntimeService().getVariable(), but it returns null.
I could get instance variable for multi-instance usertask/task using this way.


@Deployment(resources = {  ExecuteMultiinstanceSubprocess.bpmn" })
    public void test_ExecuteMultiSubprocess_should_acess_instance_elementvariable()
    {
        Map<String, Object> variables = new HashMap<String, Object>();
        List<String> collectionVariables = new ArrayList<String>();
        collectionVariables.add("elementVariable1");
        collectionVariables.add("elementVariable2");
        collectionVariables.add("elementVariable3");
        variables.put("collectionVariables", collectionVariables);

        ProcessInstance process = activitiRule.getRuntimeService().startProcessInstanceByKey("processAcsessSubprocessMultiinstanceVariable", variables);

        List<Execution> subProccesInstances = activitiRule
                .getRuntimeService()
                .createExecutionQuery()
                .activityId("subprocessMultiinstance")
                .processInstanceId(process.getProcessInstanceId())
                .list();

        Assertions.assertThat(subProccesInstances.size()).as("number of parallel sub-processes instances").isEqualTo(3);

        String elementVariable1 = (String) activitiRule.getRuntimeService().getVariable(subProccesInstances.get(0).getId(), "elementVariable");

        Assertions.assertThat(elementVariable1).as("elementVariable should be elementVariable1 but get null").isEqualTo("elementVariable1");
    }

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,
You are right. 🙂
I checked that variables are in the DB, but they are not returned from the query. (jUnit test https://github.com/martin-grofcik/activiti-unit-test-template/tree/forum-element-variable)
Could you create issue for that?
Regards
Martin