> 参考案例:【出差申请】【借款申请】,出差流程调用子流程借款申请 ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/145443_a30be568_443268.png "1.png") ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/145455_5129a11e_443268.png "2.png") ### 主子流程调用交互步骤: #### 一.主流程子流程节点设置 ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/145743_d284879d_443268.png "1.png") 说明: - (1)调用子流程:填写子流程的流程key,该案例为“joa_loan” - (2)传入变量(主流程->子流程):主流程的流程变量值传递给子流程的流程变量,例如:源变量“apply_no”,目标变量“id”,意思是流程进入子流程时把主流程的流程变量“apply_no”的值传递给子流程流程变量“id”, 主流程传入子流程的变量除此之外还有applyUserId,以及JG_LOCAL_PROCESS_ID的内置配置 ``` <activiti:in source="apply_no" target="id"/> <activiti:in source="applyUserId" target="applyUserId"/> <activiti:in source="JG_LOCAL_PROCESS_ID" target="JG_SUB_MAIN_PROCESS_ID"/> ``` - (3)传回变量(子流程->主流程):子流程的流程变量值传递回主流程的流程变量 #### 二.主流程中子流程节点被调用前配置流程节点,进行子流程表单信息的录入,信息保存是与主流程数据关联 ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/152113_5918845c_443268.png "1.png") 【流程配置】-【流程节点】配置该节点的表单组件地址,该表单应是一个可编辑的表单,页面应有保存按钮进行数据保存操作 ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/152159_b1b0bf42_443268.png "1.png") 备注: 该节点非必需,可以把该节点放到子流程作为首节点 #### 三.子流程相关设置 (1)【流程配置】-【流程节点】增加开始节点配置进入该流程是的默认单据页面组件名称,该页面组件的开发参照[【流程对接表单页面开发方法】](https://gitee.com/jeecgos/dashboard/wikis/jeecgos/jeecgbootbpm/preview?sort_id=1466761&doc_id=318601) ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/151225_35a99e01_443268.png "1.png") (2)子流程配置流程开始监听 ![输入图片说明](https://images.gitee.com/uploads/images/2019/0614/151425_8eb371bd_443268.png "1.png") 该流程监听可自行扩展,主要目的是把主流程的必要的流程变量带到子流程,或者额外增加子流程从的流程变量 ``` public class SubProcessStartListener implements ExecutionListener{ private static final long serialVersionUID = 1L; @Override public void notify(DelegateExecution execution) throws Exception { RuntimeService runtimeService = SpringContextUtils.getBean(RuntimeService.class); String mainProcessId = (String)execution.getVariable(WorkFlowGlobals.JG_SUB_MAIN_PROCESS_ID); String bizTitle = (String)runtimeService.getVariable(mainProcessId,WorkFlowGlobals.BPM_BIZ_TITLE); String businessKey = (String)runtimeService.getVariable(mainProcessId, WorkFlowGlobals.BPM_DATA_ID); execution.setVariable(WorkFlowGlobals.BPM_BIZ_TITLE, bizTitle); //子流程实例set业务号和主流程保持一致 runtimeService.updateBusinessKey(execution.getProcessInstanceId(), businessKey); } } ``` 主子流程配置完成。