{"record":{"id":"2ded42697c2d2858","repo":"flowable/flowable-engine","slug":"no-plan-item-instance-found-for-id-planiteminsta-2ded42","errorCode":null,"errorMessage":"No plan item instance found for id ${planItemInstanceId}","messagePattern":"No plan item instance found for id (.+?)","errorType":"validation","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetLocalVariablesCmd.java","lineNumber":51,"sourceCode":"        this.planItemInstanceId = planItemInstanceId;\n        this.variables = variables;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (planItemInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"planItemInstanceId is null\");\n        }\n        if (variables == null) {\n            throw new FlowableIllegalArgumentException(\"variables is null\");\n        }\n        if (variables.isEmpty()) {\n            throw new FlowableIllegalArgumentException(\"variables is empty\");\n        }\n     \n        PlanItemInstanceEntity planItemInstanceEntity = CommandContextUtil.getPlanItemInstanceEntityManager(commandContext).findById(planItemInstanceId);\n        if (planItemInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No plan item instance found for id \" + planItemInstanceId, PlanItemInstanceEntity.class);\n        }\n        planItemInstanceEntity.setVariablesLocal(variables);\n        \n        CommandContextUtil.getAgenda(commandContext).planEvaluateCriteriaOperation(planItemInstanceEntity.getCaseInstanceId());\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":33,"sourceCodeEnd":61,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetLocalVariablesCmd.java#L33-L61","documentation":"Thrown by SetLocalVariablesCmd.execute when no plan item instance exists with the given id in the CMMN engine database. Flowable looks up the PlanItemInstanceEntity via findById and raises FlowableObjectNotFoundException if absent, so the local variables cannot be set.","triggerScenarios":"Calling RuntimeService/CaseService setLocalVariables (or the SetLocalVariablesCmd command directly) with a planItemInstanceId that does not exist, was already completed/removed, or belongs to a different engine/database.","commonSituations":"Stale or hardcoded plan item instance ids, referencing an id from another case instance or environment, calling after the plan item terminated, or pointing at a case DB that was cleaned/redeployed.","solutions":["Verify the planItemInstanceId is correct and fetch it via a plan item instance query for the live case instance","Check that the plan item instance is still active (not completed/terminated) before setting variables","Confirm the command runs against the same engine/database that owns the plan item instance","Catch FlowableObjectNotFoundException and handle the missing-id case explicitly"],"exampleFix":"// before\nruntimeService.setLocalVariables(stalePlanItemInstanceId, vars);\n// after\nPlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery()\n        .caseInstanceId(caseInstanceId).planItemInstanceStateActive().singleResult();\nif (pii != null) {\n    cmmnRuntimeService.setLocalVariables(pii.getId(), vars);\n}","handlingStrategy":"validation","validationCode":"if (planItemInstanceId == null || planItemInstanceId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"planItemInstanceId required\");\n}\nPlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery()\n        .planItemInstanceId(planItemInstanceId).singleResult();\nif (pii == null) throw new IllegalArgumentException(\"Unknown plan item instance: \" + planItemInstanceId);","typeGuard":"boolean planItemInstanceExists(String id) {\n    return id != null && cmmnRuntimeService.createPlanItemInstanceQuery()\n        .planItemInstanceId(id).count() > 0;\n}","tryCatchPattern":"try {\n    cmmnRuntimeService.setLocalVariables(planItemInstanceId, vars);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Plan item instance {} not found\", planItemInstanceId, e);\n}","preventionTips":["Always resolve plan item instance ids from a live query, never hardcode them","Check plan item state (active) before writing local variables","Reuse the same engine configuration/database across calls"],"tags":["flowable","cmmn","not-found","plan-item-instance"],"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-14T05:17:10.506Z"}