Time for action – implementing a multi-instance process

To implement a multi-instance process, we have to perform the following steps:

  1. Here we will take the TrainingRequest process covered in Chapter 6, The Activiti ProcessEngine API. The TrainingRequest process is shown in the following screenshot:
    Time for action – implementing a multi-instance process
  2. We can make the multi-instance process either sequential or parallel; for that, we need to set the isSequential parameter of multi-instance. If the value is true, Activiti will execute in a sequential order; if false, it will execute in parallel. By default, the value is set to false.
  3. To iterate the Business Development task, we can set the Multi Instance property's Loop cardinality value to some positive value, as provided in the following screenshot:
    Time for action – implementing a multi-instance process
  4. On setting the Multi Instance property and deploying the process to the Activiti Engine, the graphical view of the process will be similar to the following screenshot:
    Time for action – implementing a multi-instance process
  5. On setting the loopCardinality value, the task will execute for that number of times.
  6. Instead of setting the static value to loopCardinality, we can set a dynamic value too, as shown in the highlighted code in the following block:
     <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}" 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>
  7. You can also assign the collection of data for the multi-instance of a task as follows:
    <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}" 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" activiti:collection="BDMList"
            activiti:elementVariable="bdmName">
             </multiInstanceLoopCharacteristics>
        </userTask>

What just happened?

We have understood the use of the multi-instance property for Activiti and various ways in which we can use the multi-instance property.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset