启动流程

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppService;
import org.joget.apps.app.service.AppUtil;
import org.joget.workflow.model.service.WorkflowManager;
import org.joget.workflow.model.WorkflowAssignment;
import org.joget.workflow.model.WorkflowProcess;
  
public Object execute(WorkflowAssignment assignment, AppDefinition appDef, HttpServletRequest request) {
    AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
    WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
     
    //get current record id
    String recordId = appService.getOriginProcessId(assignment.getProcessId());
     
    //get process
    WorkflowProcess process = appService.getWorkflowProcessForApp(appDef.getAppId(), appDef.getVersion().toString(), "process2");
     
    //start process
    if(processId == null || processId.trim().equals("")){
    //如果在link表中查不到processId ,说明流程发起之后没有经过任何变更,表单Id就是InstanceId
	    workflowManager.processAbort(recordId);
	}else{
	    workflowManager.processAbort(processId);
	}
     
    return null;
}
  
//call execute method with injected variable
return execute(workflowAssignment, appDef, request);


 根据自定义ID终止流程(Code from Hugo)

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

//constant value
String processInstanceId = "1529_expenseclaim_process1"; //set the oldest ID here

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

WorkflowProcessLinkDao dao = (WorkflowProcessLinkDao) AppUtil.getApplicationContext().getBean("workflowProcessLinkDao");
Collection processLinks = dao.getLinks(processInstanceId);

boolean found = false;
WorkflowActivity act;
for (WorkflowProcessLink l : processLinks) {
    try {
        WorkflowProcess process = workflowManager.getRunningProcessById(l.getProcessId());
        if (process != null && process.getId() != null) {
            //check if process is active
            //System.out.println("Process state --> " + process.getState());
            if(process.getState() != null && process.getState().startsWith("open")){
                processInstanceId = process.getInstanceId();
				break;
                System.out.println("Latest active process instance ID --> " + processInstanceId);
            }
        }
   } catch(Exception e){
        System.out.println(e.toString());
   }
}
workflowManager.processAbort(processInstanceId);

使用时仅需要修改 recordId 获取的方式


相关的文章