Versions Compared

Key

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

...

非流程启动表单发起流程

1.进入普通表单设计器,增加表单后续处理工具

Info

在上方的保存为草稿表单中,由于设置了该表单为启动流程表单,所以【不能】作为发起流程表单。

如果需要【草稿表单】发起流程,则需要复制【发起流程表单】,新建【普通表单】发起流程


2.使用以下代码,填入代码块中(注意其中的变量设置)

Code Block
// 非流程启动表单发起流程
import java.util.HashMap;
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.WorkflowProcessResult;
import org.joget.workflow.model.service.WorkflowManager;
import org.joget.workflow.model.WorkflowAssignment;
import org.joget.workflow.model.WorkflowProcess;

	// 流程ID, 根据需要修改
    String processId = "eform_sourcing";
 
    String status = "#form.geg_sourcing.processStatus#";
    String requester = "#form.geg_sourcing.requestUser#";
    String endorser = "#form.geg_sourcing.endorser#";
    String approver = "#form.geg_sourcing.approver#";
    String refNo = "#form.geg_sourcing.sourcingID#";
    
    public Object execute(WorkflowAssignment assignment, AppDefinition appDef, HttpServletRequest request) {
        AppService appService = (AppService) AppUtil.getApplicationContext().getBean("appService");
        WorkflowManager workflowManager = (WorkflowManager) AppUtil.getApplicationContext().getBean("workflowManager");
        //get process
        WorkflowProcess process = appService.getWorkflowProcessForApp(appDef.getAppId(), appDef.getVersion().toString(), processId);
 
        Map variables = new HashMap();
        variables.put("status",status);
        variables.put("requester",requester);
        variables.put("Endorser",endorser);
        variables.put("Approver",approver);
        variables.put("refNo",refNo);
        
        //start process
        WorkflowProcessResult result = workflowManager.processStart(process.getId(), null, variables, null, "#form.geg_sourcing.id#", false);
        System.out.println(result.getProcess().getId());
        return null;
    }
 
//call execute method with injected variable
   return execute(workflowAssignment, appDef, request);

...