Parallel Multi-Instance User task getting created with last employee details

Hi All,
I am developing a scenario on Camunda bpm Modeler 5 and bpm run 7.17.
Scenario:
using a service task to invoke an external rest-api using http-connector and that external rest api sends response as follows with multiple employees info in json format.
[
{“regId":“0XFY1FX00W”,“fname”:“abc”,“lname”:“def”,“email”:"abc.def@gmail.com”},
{“regId":“0XFY1F000X”,“fname”:“ghi”,“lname”:“jklm”,“email”:"ghi.jklm@ymail.com”},
{“regId":“0XFY1F000Y”,“fname”:“nop”,“lname”:“qrs”,“email”:"nop.qrs@xmail.com”},
{“regId":“0XFY1F000Z”,“fname”:“tuv”,“lname”:“wxyz”,“email”:"tuv.wxyz@zmail.com”}
]

I am trying to create 4 user tasks with those 4 employees and those user tasks should be populated with those employee first name and last names.
I have used parallel multi-instance and I succeeded with that 4 user tasks creation but all the user tasks contain last employee details i.e. “fname”:“tuv”,“lname”:“wxyz”.

Please let me know how to achieve that i.e. the user tasks should contain 4 different employee details?

Note: I have tested with sequence multi-task and it is working as expected and My requirement is to use user task and not any subprocess.

Thanks in advance

Hi @thiru.lmn,

Could you please share with us your model.

Hi @hassang ,
Thank you very much for your response.

PFA model.
ServiceTaskDemo.bpmn (4.0 KB)

Hi @thiru.lmn,

The employee element variable is created as a local variable so for each instance of the multi-instance task a separate local variable is created. This variable can live for the period from the creation of the instance to the end of it.

Using an execution listener or a task listener attached to the multi-instance task, you can access each created instance. Kindly find a simplified attached example showing data printed out using an execution listener.

multi-instance-task-process.bpmn (3.1 KB)

Hi @hassang ,
Thank you for your model :slight_smile:

The following are the observations in your model and behavior is similar to my model i.e. both are not working as expected.

  1. your model contains #{users.elements()} for collection and i have used ${S(response).elements()} for the same.
  2. your model contains “user” as Element Variable and i have used employee for the same.
    3. you printed the “name” on console and it is working fine and i have modified user task name in your model and it is also working fine. Even my model is behaving similar.
  3. I tried with my model and your model as well to populate content on user task for a text field and the behavior is same.
    i.e. your model always creating the user tasks with the name as “User 2” always for both the tasks where as my model creating the user tasks with the last employee details.
    PFA pics for the same.

So concluding that its not fixed the issue.



multi-instance-task-process.bpmn (3.2 KB)

Hi @thiru.lmn,

Could you please share your form…
You should bind with a local task variable.

Hi @hassang
PFA file for the same.

it is giving error while uploading the form file in this community.
Please see the json below for the same.

{
“components”: [
{
“label”: “First Name”,
“type”: “textfield”,
“id”: “Field_1guxlgf”,
“key”: “fname”
},
{
“label”: “Last Name”,
“type”: “textfield”,
“id”: “Field_0rrsufl”,
“key”: “lname”
}
],
“type”: “default”,
“id”: “Form_18khu4c”,
“exporter”: {
“name”: “Camunda Modeler”,
“version”: “5.0.0”
},
“executionPlatform”: “Camunda Platform”,
“executionPlatformVersion”: “7.17.0”,
“schemaVersion”: 4
}

Hi @thiru.lmn,

Okay, both variables fname and lname should be created as local variables.

Use the method setVariableLocal instead of setVariable as in below

execution.setVariableLocal('fname',S(execution.getVariable('employee')).prop('fname').value());
execution.setVariableLocal('lname',S(execution.getVariable('employee')).prop('lname').value());

Hi @thiru.lmn,

But I am afraid that this is not going to work with Camunda forms as form fields are created as process instance variables whereas your need is to bind to local task variables. I believe that you need to use embedded forms instead of Camunda forms in this case.

1 Like

Hi @hassang
Finally, its working for camunda forms also.

Thank you very much for your time and Support :slight_smile:

2 Likes

Hi @thiru.lmn, would you please be so kind as to share your final fully functioning process model?
@hassang thank you for your generous and thoughtful guidance across the goal line on this!!!
I’m interested to do something very similar so thank you both for sharing :pray:

Hi @Paul_Roth ,
PFA process and form below.

Thank you :slight_smile: @hassang
ServiceTaskDemo.bpmn (4.1 KB)

Test.Form
{
“components”: [
{
“label”: “First Name”,
“type”: “textfield”,
“id”: “Field_1guxlgf”,
“key”: “fname”
},
{
“label”: “Last Name”,
“type”: “textfield”,
“id”: “Field_0rrsufl”,
“key”: “lname”
}
],
“type”: “default”,
“id”: “Form_18khu4c”,
“exporter”: {
“name”: “Camunda Modeler”,
“version”: “5.0.0”
},
“executionPlatform”: “Camunda Platform”,
“executionPlatformVersion”: “7.17.0”,
“schemaVersion”: 4
}

1 Like

Thank you very much!!