AnsweredAssumed Answered

activiti 7 how can we aasociate a task variable to User Task

Question asked by parul.b.aggarwal on Feb 28, 2019

We have a usecase where we need to set some custom metadata with the User Task to be created in the XML.

For eg. we need to insert a record in DB with 5-6 custom fields which are not stored in activiti as part of the Task instance. We have used two approaches

Approach 1:- We have tried associating task variables to user task in the XML as in activiti 6 but the variables are not getting associated with the task created by activiti.

 

XML:-

 <bpmn2:userTask id="Task_0bmwliu" name="Part Installation">
      <bpmn2:dataObject id="taskId1" name="taskId1" itemSubjectRef="xsd:string">
  <bpmn2:extensionElements>
  <bpmn2:value>jdfsdjr834738nvfdjkndk</bpmn2:value>
   </bpmn2:extensionElements>
   </bpmn2:dataObject>
      <bpmn2:incoming>SequenceFlow_1r1c9sc</bpmn2:incoming>
      <bpmn2:outgoing>SequenceFlow_0kbqp3t</bpmn2:outgoing>
    </bpmn2:userTask>
     

 

Approach 2:- We have implemented the Task Listener and tried to add the variable to that task but there is no provision in the API to add task variable to the Task Entity returned by TaskCreatedEvent. and there is no association in the XML.

 

Code:-

 

else if (runtimeEvent instanceof TaskCreatedEvent) {
            logger.info("Do something, task is created: " + runtimeEvent.toString());
            TaskCreatedEvent taskEvent = (TaskCreatedEvent)runtimeEvent;
            Task task = taskEvent.getEntity();
            // get the metadata passed in to process instance as variable

 

         
        }

Outcomes