AnsweredAssumed Answered

Regarding assigning candidate group for use task dynamically

Question asked by indrayani on May 25, 2016
Latest reply on Nov 25, 2016 by mrc0mm0n
Hi,

I am running activiti from liferay.
I am trying to set candidate group for user task dynamically for which I have tried below solutions which are not working.
This is for liferay 6.2 CE GA6 and activiti version 5.18.0
Please let me know if I have missed anything or If you have a better solution.

Solution 1 :
Its regarding settting candidate group for a user task using proccess variable.
below is the bpmn code :

  <userTask id="Review" name="Review"  activiti:candidateGroups=${assignee}>
      <extensionElements>
        <activiti:formProperty id="outputTransition" name="output Transition" type="enum">
          <activiti:value id="Approve" name="Approve"></activiti:value>
          <activiti:value id="Reject" name="Reject"></activiti:value>
        </activiti:formProperty>
      </extensionElements>
    </userTask>

here , assignee is the process variable which is already set.

While executing the workflow, I am getting following exception :

13:42:01,326 INFO  [http-bio-8080-exec-10][LiferayGroupsUtil:54] Convert groups : [ ${assignee} ]
13:42:01,329 WARN  [http-bio-8080-exec-10][LiferayGroupsUtil:94] Cannot assign task to role ${assignee}
com.liferay.portal.NoSuchRoleException: No Role exists with the key {companyId=20155, name=${assignee}}


——————————————————————————————
Solution 2 :

I also tried below xml code but I am still getting the same exception :
Here, I have the multiInstanceLoopCharacteristics.
 
<userTask id="Review" name="Review"  activiti:candidateGroups=${assignee}>
       <multiInstanceLoopCharacteristics isSequential="false"
        activiti:collection="candidateGrp" activiti:elementVariable="assignee" >
       <completionCondition>${nrOfCompletedInstances/nrOfInstances >= 0.6 }</completionCondition>
     </multiInstanceLoopCharacteristics>
      <extensionElements>
        <activiti:formProperty id="outputTransition" name="output Transition" type="enum">
          <activiti:value id="Approve" name="Approve"></activiti:value>
          <activiti:value id="Reject" name="Reject"></activiti:value>
        </activiti:formProperty>
      </extensionElements>
    </userTask>

——————————————————————————————
Solution 3:

I also tried to set the candidate group dynmically using DynamicBpmnService, Please check the code below :
For this approach, I used activiti version 5.19.0
I replaced the activiti engine jar from liferay > tomcat> webapp > activiti-web > web-inf >lib
          

       @Override
   public void notify(DelegateExecution execution) {
      try {
      EngineServices engineServices = execution.getEngineServices();
      DynamicBpmnService dynamicBpmnService = engineServices.getDynamicBpmnService();
      ObjectNode infoNode = dynamicBpmnService.changeUserTaskCandidateGroup(
               "Review", "Power User", false);
      dynamicBpmnService.saveProcessDefinitionInfo("procDefId", infoNode);
      System.out.println("——saveProcessDefinitionInfo——=saved");
      
      } catch (Exception e) {
         System.out.println("——error");
         e.printStackTrace();
      }
      List<String> list = new ArrayList<String>();
      list.add("Power User");
      execution.setVariable("candidateGrp",list);
   }

I am getting following exception while executing this code :

WARN  [http-bio-8080-exec-10][ProxyMessageListener:81] org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))
### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity.insertProcessDefinitionInfo-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_PROCDEF_INFO(ID_, PROC_DEF_ID_, REV_, INFO_JSON_ID_)     values(?,             ?,            1,            ?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))
### The error may involve org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntity.insertProcessDefinitionInfo-Inline
### The error occurred while setting parameters
### SQL: insert into ACT_PROCDEF_INFO(ID_, PROC_DEF_ID_, REV_, INFO_JSON_ID_)     values(?,             ?,            1,            ?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`lportal`.`act_procdef_info`, CONSTRAINT `ACT_FK_INFO_PROCDEF` FOREIGN KEY (`PROC_DEF_ID_`) REFERENCES `act_re_procdef` (`ID_`))



Thank you,
Indrayani

Outcomes