Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import java.util.*;
import org.joget.apps.app.service.*;
import org.joget.workflow.model.*;
import org.joget.workflow.model.service.*;
import org.joget.workflow.model.dao.WorkflowProcessLinkDao;

//需要修改的值
//apply_id 对应 主流程设置的hash变量
String processInstanceId = "#variable#assignment.LoARequest_id#processId#";

// activityDefId 的值对应主流程中activityId
//为waitingForResponse 的 activity
String activityDefId = "waitingForResponse";

//utility bean
WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");  
WorkflowUserManager workflowUserManager = (WorkflowUserManager) AppUtil.getApplicationContext().getBean("workflowUserManager");

//get current user username and temporary set current user to roleAnonymous to get the assignment
String username = workflowUserManager.getCurrentUsername();

workflowUserManager.setCurrentThreadUser("roleAnonymous");

WorkflowProcessLinkDao dao = (WorkflowProcessLinkDao) AppUtil.getApplicationContext().getBean("workflowProcessLinkDao");

//get assignment
Collection assignments = workflowManager.getAssignmentList(null, null, processInstanceId, activityDefId, null, null, null, 1);

//add 2  >>>>>>>>>>>>
if (assignments == null || assignments.isEmpty()) {
    Collection processLinks = dao.getLinks(processInstanceId);
    if (!processLinks.isEmpty()) {
        for (WorkflowProcessLink l : processLinks) {
            assignments = workflowManager.getAssignmentList(null, null, l.getProcessId(), activityDefId, null, null, null, 1);
            if (assignments != null && !assignments.isEmpty()) {
                break;
            }
        }
    }
}
if (assignments != null && !assignments.isEmpty()) {
    WorkflowAssignment ass = (WorkflowAssignment) assignments.iterator().next();
    String actId = ass.getActivityId();
    //accept and complete assignment
    workflowManager.assignmentAccept(actId);
    workflowManager.assignmentComplete(actId, new HashMap());
}

//set the current user back to original
workflowUserManager.setCurrentThreadUser(username);

...