Is it not possible to assign values in multi-instance activity

Hi,

I’m beginner to camunda and exploring few options related to sequential/parallel using multi-instance activity for a user task.

I’ve ‘john’ as an assignee and for multi-instance variable are as follows:

loopCardinality = 5; Collection=john; elementVariable=assignee.

 <bpmn:userTask id="Task_1n0xwel" name="Approve Loan" camunda:formKey="embedded:app:forms/approve-loan.html" camunda:assignee="john">
      <bpmn:extensionElements>
        <camunda:taskListener class="com.suhas.madap.camunda.loanapproval.TaskAssignmentListener" event="assignment" />
      </bpmn:extensionElements>
      <bpmn:incoming>SequenceFlow_166tlxj</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1hilsnz</bpmn:outgoing>
      <bpmn:multiInstanceLoopCharacteristics isSequential="true" camunda:collection="john" camunda:elementVariable="assignee">
        <bpmn:loopCardinality xsi:type="bpmn:tFormalExpression">5</bpmn:loopCardinality>
      </bpmn:multiInstanceLoopCharacteristics>
    </bpmn:userTask>

is this correct?

our requirement is I’ve to assign user task sequentially to john, mary, peter.

Thanks,
Suhas Madap.

Hi Suhas Madap,

  • collection is the name of the process variable that you want to iterate over (e.g. a list with the values john, mary, peter is going to result in three tasks). If you use collection, the loopCardinality should not be defined
  • elementVariable is the name of the process variable the element will be assigned to (assuming you set this to assignee, then assignee will have the value john for the first instance, mary for the second instance, etc.)
  • camunda:assignee is the name of the assignee. It can also be an EL expression and that way, you can set it dynamically based on a process variable. That means, setting it to ${assignee} should do the trick

See the docs on multi-instance for details.

Cheers,
Thorben

1 Like

Thanks Thorben. So collection process variable cannot hold values (ex: camunda:collection=“john,mary,peter” etc.), it can only hold a variable name which intern gets evaluated by org.camunda.bpm.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior#evaluateCollectionVariable().

Is my understanding correct?

can I model like camunda:assignee=“john,mary,peter” and camunda:collection="${assignee}"?

Hi @revsmadap,

I think there is still a misunderstanding how these attributes work. Have a look at the following test case:

Cheers,
Thorben

1 Like

Thanks Thorben. I’m able to achieve it using test case. I’m trying to understand, how things are co-related from modeling perspective. The reason why I’m asking this because, modeling will be done mostly by business users.

Hi @revsmadap,

I think adding technical properties to the model should not be done by business users. Getting those properties right is not a trivial task as it requires good knowledge of how Camunda and its API work.

If there is a business requirement on how assignees are to be determined, then business users could document that requirement visually in the model (e.g. via BPMN annotations or via the name of the lane the task is contained in). Technical users can then implement that by setting the correct technical properties.

Cheers,
Thorben

2 Likes

Hi Thorben,

Thanks a lot. Exactly, I’m trying to understand how things work under the hood. I could understand little bit through debugging.

So if I start a process from tasklist web application, can we achieve the same?

Thanks,
Suhas Madap

Can you please clarify what you mean with the same here?

Hi Thorben,

Sorry! question should have been little clear. I mean startProcessInstance with variables i.e. assigneeList. Similar to test case.

Map<String, Object> vars = new HashMap<String, Object>();
    List<String> assigneeList = Arrays.asList("kermit", "gonzo", "fozzie");
    vars.put("assigneeList", assigneeList);
    runtimeService.startProcessInstanceByKey("miSequentialUserTasks", vars);

Thanks,
Suhas

Hi Suhas,

You can implement an embedded start form to post a JSON-serialized Java variable. We have an example on how to post a custom POJO. Posting a java.util.ArrayList object should work in a similar way.

Cheers,
Thorben

just for reference as I suppose @revsmadap was asking something similar like me: