flowable / flowable-engine

A compact and highly efficient workflow and Business Process Management (BPM) platform for developers, system admins and business users.
https://www.flowable.org
Apache License 2.0
7.85k stars 2.59k forks source link

After running runtimeService().deleteProcessInstance(processInstance.getId()) to delete the parent process instance, the CallActivity subprocessInstance query is null #3916

Closed MoringMartin closed 3 months ago

MoringMartin commented 3 months ago

After running runtimeService().deleteProcessInstance(processInstance.getId()) to delete the parent process instance, the CallActivity subprocessInstance query is null

After running runtimeService().deleteProcessInstance(processInstance.getId()) to delete the parent process instance, the CallActivity subprocessInstance i can query

Code

public MetaWorkData taskRefuse(MetaWorkData metaWorkData, Map<String, Object> variables) {
        taskComplete(metaWorkData, variables);

        MetaWorkFlow metaWorkFlow = workFlowService.queryById(metaWorkData.getFlowId());
        MetaWorkFlowAssert.EMPTY_META_WORK_FLOW.isNotBlank(metaWorkFlow);

        List<MetaWorkFlow> allWorkFlows = new ArrayList<>();
        collectParentAndChildWorkflows(metaWorkFlow, allWorkFlows);

        allWorkFlows.forEach(flow -> {
            String processInstanceId = flow.getThirdBusinessKey();
            ProcessInstance processInstance = processEngine.getRuntimeService()
                    .createProcessInstanceQuery()
                    .processInstanceId(processInstanceId)
                    .singleResult();
            MetaWorkFlowAssert.FLOWABLE_PROCESS_INSTANCE_EMPTY.isNotBlank(processInstance);
            processEngine.getRuntimeService().deleteProcessInstance(processInstance.getId(), "Fail the audit");
            doAfterProcessInstanceChange(flow, FlowStatusTypeEnum.REFUSED);
        });

        return metaWorkData;
    }

Additional context This was using Flowable ### 7.1.0-SNAPSHOT.

filiphr commented 3 months ago

This works as designed. When you delete a parent process, it's children will also be deleted.

e.g. if you have Parent Process -> Call Activity Process. When you delete the parent process, the call activity process will also be deleted.