{"record":{"id":"6215f9cff18733b5","repo":"flowable/flowable-engine","slug":"the-current-flow-element-of-the-requested-is-not","errorCode":null,"errorMessage":"The current flow element of the requested  is not an ad-hoc sub process","messagePattern":"The current flow element of the requested  is not an ad-hoc sub process","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CompleteAdhocSubProcessCmd.java","lineNumber":50,"sourceCode":"\n    private static final long serialVersionUID = 1L;\n\n    protected String executionId;\n\n    public CompleteAdhocSubProcessCmd(String executionId) {\n        this.executionId = executionId;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);\n        ExecutionEntity execution = executionEntityManager.findById(executionId);\n        if (execution == null) {\n            throw new FlowableObjectNotFoundException(\"No execution found for id '\" + executionId + \"'\", ExecutionEntity.class);\n        }\n\n        if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {\n            throw new FlowableException(\"The current flow element of the requested \" + execution + \" is not an ad-hoc sub process\");\n        }\n\n        List<? extends ExecutionEntity> childExecutions = execution.getExecutions();\n        if (childExecutions.size() > 0) {\n            throw new FlowableException(\"Ad-hoc sub process has running child executions that need to be completed first. \" + execution);\n        }\n\n        ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());\n        outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());\n\n        executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);\n\n        CommandContextUtil.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);\n\n        return null;\n    }\n\n}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/CompleteAdhocSubProcessCmd.java#L32-L68","documentation":"CompleteAdhocSubProcessCmd requires the execution's current flow element to actually be an AdhocSubProcess. Flowable throws FlowableException when the execution points at a different BPMN element type.","triggerScenarios":"Calling completeAdhocSubProcess(executionId, ...) on an execution whose currentFlowElement is a user task, subprocess, or other element instead of an ad-hoc sub-process.","commonSituations":"Confusing execution ids of activities inside the ad-hoc sub-process with the execution hosting the sub-process itself; using the API on a regular embedded sub-process.","solutions":["Pass the execution id of the execution whose current flow element is the ad-hoc sub-process (e.g. the child execution of the process instance).","Confirm the BPMN model declares <adhocSubProcess>, not a regular subProcess.","Inspect runtimeService.createExecutionQuery().executionId(id).singleResult() and its activityId against the model."],"exampleFix":"// before\nruntimeService.completeAdhocSubProcess(innerTaskExecutionId, outcome);\n// after\n// use the execution at the ad-hoc sub-process level\nruntimeService.completeAdhocSubProcess(adhocSubProcessExecutionId, outcome);","handlingStrategy":"validation","validationCode":"ExecutionEntity e = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(executionId).singleResult();\n// ensure e.getActivityId() maps to the adhocSubProcess element in the BPMN model, not an inner activity","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.completeAdhocSubProcess(executionId, outcome);\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"not an ad-hoc sub process\")) {\n        // wrong execution id passed; locate the sub-process execution\n    }\n}","preventionTips":["Locate the execution whose activityId equals the ad-hoc sub-process element id.","Verify the BPMN XML uses <adhocSubProcess> and you are not targeting a regular subprocess."],"tags":["flowable","bpmn","ad-hoc-subprocess","wrong-target"],"backgroundTag":"invalid-argument-value","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}