cancel
Showing results for 
Search instead for 
Did you mean: 

Multi-instance cardinality does not work with a variable

kecondezo
Champ in-the-making
Champ in-the-making
I have the next xml of my bpmn task where I am trying that the loopcounter be variable (watch the line <loopCardinality>${loopCounter}</loopCardinality> ) And This variable is part of the start event form.
     <startEvent id="startevent1" name="Start">
      <extensionElements>
        <activiti:formProperty id="customerName" name="Name" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="customerEmail" name="email" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="trainingTopic" name="Topic for Training" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="trainingDate" name="Training Date" type="date" datePattern="dd-MM-yy" required="true"></activiti:formProperty>
        <activiti:formProperty id="loopCounter" name="Contador" type="long"></activiti:formProperty>
      </extensionElements>
    </startEvent>
    <userTask id="usertask1" name="Business Development Executive" activiti:assignee="gonzo">
      <extensionElements>
        <activiti:formProperty id="custName" name="Customer Name" type="string" expression="${customerName}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="trainTopic" name="Training Topic" type="string" expression="${trainingTopic}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="trainDate" name="Training Date" type="date" expression="${trainingDate}" datePattern="dd-MM-yy" writable="false"></activiti:formProperty>
        <activiti:formProperty id="trainerName" name="Trainer Name" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="trainerMailId" name="Trainer ID" type="string" required="true"></activiti:formProperty>
      </extensionElements>
      <multiInstanceLoopCharacteristics isSequential="true">
        <loopCardinality>${loopCounter}</loopCardinality>
      </multiInstanceLoopCharacteristics>
    </userTask>


The issue is that when I start an instance, this automatically create 2  Business Development Executive tasks at the same time which is something that does not happen if I put the  loopCardinality variable fix ( I mean put 5 instead of loopcounter). Well the instance starts and as I said now "gonzo" has to Business Development Executive task but when gonzo try to complete the tasks this error message appears in activiti explorer:
 User Task Should not be signalled before complete 


So gonzo cannot close the tasks.
8 REPLIES 8

kecondezo
Champ in-the-making
Champ in-the-making
By the way I am using the 5.19.0 release.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

Can you create jUnit test please?
https://forums.activiti.org/content/sticky-how-write-unit-test

Regards
Martin

kecondezo
Champ in-the-making
Champ in-the-making
Where is the new jira linkg, the link that is posted by  Joe Barrez is deprecated (codehouse servicess are not enable).
I have the zip file but I do not know where to upload it due to this page does not support it.
When I tried to run the unit test, there this error message, even when the xml has been deployed in the activiti explorer without problems:
<code>
Unknown property used in expression: ${loopCounter}
</code>
See the full trace in the attached file.

kecondezo
Champ in-the-making
Champ in-the-making
I have created the jira ticket with the jUnit test https://activiti.atlassian.net/browse/ACT-4173

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi kecondezo,

The issue is loopCounter is reserved key word by default (see doc). You have two options:
- rename loop variable
- change default loop variable name.

If I changed test to:


public void test() {
  Date date = new Date();
  Map<String, Object> variables = new HashMap<String, Object>();
  variables.put("customerName", "Calimba");
  variables.put("customerEmail",
  "kecondezo@gmail.com");
  variables.put("trainingTopic", "Activiti");
  variables.put("trainingDate", date);
  variables.put("trainerName", "Kennyman");
  variables.put("trainerMailId","kecondezo@gmail.com");
  variables.put("loopC",5);
  //ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("my-process");
  ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("trainingProcess", variables);
  assertNotNull(processInstance);

  Task task = activitiRule.getTaskService().createTaskQuery().singleResult();
  assertEquals("Business Development Executive", task.getName());
}

and process definition:

      <multiInstanceLoopCharacteristics isSequential="true">
        <loopCardinality>${loopC}</loopCardinality>
      </multiInstanceLoopCharacteristics>

The test has passed.

Regards
Martin

kecondezo
Champ in-the-making
Champ in-the-making
Thanks Martin,
I change the name of the variable for  loopC, in the JUnit test I am still getting the same message
<code> Unknown property used in expression: ${loopC} </code>
but when I tried the change directly into Activity Explorer it works fine.
So can you attach your project into Jira to see what is wrong with my JUnit environment?. This is not the first time the JUnit thorows this error and the model works fine in the Activiti Explorer.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi,

I think you missed this line in the jUNit test:


ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("trainingProcess", variables);

Regards
Martin

kecondezo
Champ in-the-making
Champ in-the-making
Yeah!!! you are right, thanks for the explanation!! everithing goes finel.