{"record":{"id":"993cdd2b83eb56d1","repo":"flowable/flowable-engine","slug":"cannot-find-plan-item-instance-for-id-planitemin","errorCode":null,"errorMessage":"Cannot find plan item instance for id ${planItemInstanceId}","messagePattern":"Cannot find plan item instance for id (.+?)","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractNeedsPlanItemInstanceCmd.java","lineNumber":70,"sourceCode":"        this.planItemInstanceId = planItemInstanceId;\n        this.variables = variables;\n        this.formVariables = formVariables;\n        this.formOutcome = formOutcome;\n        this.formInfo = formInfo;\n        this.localVariables = localVariables;\n        this.transientVariables = transientVariables;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (planItemInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"Plan item instance id is null\");\n        }\n\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        PlanItemInstanceEntity planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findById(planItemInstanceId);\n        if (planItemInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find plan item instance for id \" + planItemInstanceId, PlanItemInstanceEntity.class);\n        }\n\n        if (formInfo != null) {\n            FormService formService = CommandContextUtil.getFormService(commandContext);\n            if (formService == null) {\n                throw new FlowableIllegalStateException(\"Form engine is not initialized\");\n            }\n\n            Map<String, Object> variablesFromFormSubmission = formService.getVariablesFromFormSubmission(planItemInstanceEntity.getPlanItemDefinitionId(), \n                    planItemInstanceEntity.getPlanItemDefinitionType(), planItemInstanceEntity.getCaseInstanceId(), planItemInstanceEntity.getCaseDefinitionId(), \n                    ScopeTypes.CMMN, formInfo, formVariables, formOutcome);\n\n            FormFieldHandler formFieldHandler = cmmnEngineConfiguration.getFormFieldHandler();\n            formFieldHandler.handleFormFieldsOnSubmit(formInfo, null, null, planItemInstanceEntity.getCaseInstanceId(), ScopeTypes.CMMN, variablesFromFormSubmission,\n                    planItemInstanceEntity.getTenantId());\n\n            planItemInstanceEntity.setVariables(variablesFromFormSubmission);\n        }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractNeedsPlanItemInstanceCmd.java#L52-L88","documentation":"FlowableObjectNotFoundException thrown in AbstractNeedsPlanItemInstanceCmd.execute when PlanItemInstanceEntityManager.findById returns null for the supplied id. The id was non-null but no plan item instance exists in the runtime tables (ACT_CMMN_RU_PLAN_ITEM_INST). Common when the plan item already completed or the id is from history.","triggerScenarios":"Completing/triggering a plan item that already reached a terminal state (completed/terminated/exited) and whose runtime row was removed; using a historic plan item instance id; wrong database or tenant; id typo.","commonSituations":"Double-submission of a form (second call after plan item completed); case instance terminated concurrently by another user; using planItemInstanceId from a completed case's history endpoint.","solutions":["Query cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(id).singleResult() first and check state is active before completing","Handle double submissions idempotently in your client (disable buttons/track submitted ids)","Use cmmnHistoryService for data about completed plan items","Verify you are querying the correct engine/database/tenant"],"exampleFix":"// before\ncmmnTaskService.completePlanItemPlanForm(planItemInstanceId, caseInstanceId, formInfo, variables, null);\n// after\nPlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemInstanceId).singleResult();\nif (pii == null || !PlanItemInstanceState.ACTIVE.equals(pii.getState())) {\n    throw new IllegalStateException(\"Plan item \" + planItemInstanceId + \" is not active\");\n}\ncmmnTaskService.completePlanItemPlanForm(planItemInstanceId, caseInstanceId, formInfo, variables, null);","handlingStrategy":"validation","validationCode":"PlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemInstanceId).singleResult();\nif (pii == null) throw new IllegalStateException(\"Plan item instance \" + planItemInstanceId + \" not found or already completed\");","typeGuard":null,"tryCatchPattern":"try { cmmnTaskService.completePlanItemPlanForm(...); }\ncatch (FlowableObjectNotFoundException e) { log.info(\"Plan item {} already completed/removed\", planItemInstanceId); }","preventionTips":["Check plan item state is ACTIVE before completing","Make form submissions idempotent to survive double clicks","Use cmmnHistoryService for completed plan item data","Watch for concurrent case termination invalidating plan item ids"],"tags":["flowable","cmmn","plan-item","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}