call activity 获取父流程实例ID

描述

activiti中内嵌子流程(call activity)是新启动一个流程,该子流程和父流程没有父子关系。该子流程的proc_inst_id_的parent_id_是空的。如果想要获取父流程的proc_inst_id_,可以通过执行环境(id_)和父执行环境(super_exec_)来获取。上述字段都是act_ru_execution表中。

实现

配置子流程start监听器,监听器中去获取父流程实例ID

@Component
@Slf4j
public class CallActivityPidListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) throws Exception {
        ExecutionEntity executionEntity = (ExecutionEntity) execution;
        ExecutionEntity processInstance = executionEntity.getProcessInstance();
        ExecutionEntity superExecution = processInstance.getSuperExecution();
        if(superExecution != null) {
            String superProcessInstanceId = superExecution.getProcessInstanceId();
            log.info("processInstanceId:{},pid:{}", processInstance.getId(), superProcessInstanceId);
        }
    }
}

字段关系

image.png

表中第三条记录是流程实例ID为2830018,执行环境ID为2830018的子流程记录。该记录的父执行环境ID为2830016,通过父执行环境ID定位到第二条记录,从而获取父流程实例ID2830001

引用

Get Parent ProcessInstance Id from a SubProcess CallActivity

你可能感兴趣的:(call activity 获取父流程实例ID)