{"record":{"id":"9674bf5f26a75596","repo":"flowable/flowable-engine","slug":"no-plan-item-instance-found-for-id-planiteminsta-9674bf","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/SetLocalVariableCmd.java","lineNumber":48,"sourceCode":"    \n    public SetLocalVariableCmd(String planItemInstanceId, String variableName, Object variableValue) {\n        this.planItemInstanceId = planItemInstanceId;\n        this.variableName = variableName;\n        this.variableValue = variableValue;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (planItemInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"planItemInstanceId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variable name is null\");\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.setVariableLocal(variableName, variableValue);\n        \n        CommandContextUtil.getAgenda(commandContext).planEvaluateCriteriaOperation(planItemInstanceEntity.getCaseInstanceId());\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":30,"sourceCodeEnd":58,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetLocalVariableCmd.java#L30-L58","documentation":"After validating inputs, SetLocalVariableCmd looks up the plan item instance via PlanItemInstanceEntityManager.findById(). If no row exists for the given id, it throws FlowableObjectNotFoundException naming the id and PlanItemInstanceEntity.class. The id was well-formed but does not correspond to any existing plan item instance.","triggerScenarios":"Calling CmmnRuntimeService.setLocalVariable with an id of a plan item instance that was deleted, belongs to a completed/terminated case (moved to history), was never created in this database, or an id from a different engine/table.","commonSituations":"Stale ids stored in external systems after the case instance ended, running against a different database/environment (test vs prod), reusing ids across Flowable versions or a cmmn vs process engine confusion.","solutions":["Verify the case instance is still active and the plan item instance exists via CmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(id).singleResult().","Confirm you are connected to the database where the case instance actually runs (not another environment).","Guard against using ids of completed plan items; query history (CmmnHistoryService) if you need historical data instead."],"exampleFix":"// before\ncmmnRuntimeService.setLocalVariable(planItemId, \"flag\", true); // id may be stale\n// after\nPlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemId).singleResult();\nif (pii != null) {\n    cmmnRuntimeService.setLocalVariable(planItemId, \"flag\", true);\n}","handlingStrategy":"validation","validationCode":"PlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery()\n        .planItemInstanceId(planItemId).singleResult();\nif (pii == null) {\n    throw new IllegalStateException(\"Plan item instance \" + planItemId + \" does not exist (case may be completed)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    cmmnRuntimeService.setLocalVariable(planItemId, name, value);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Plan item instance {} not found; case may have ended: {}\", planItemId, e.getMessage());\n}","preventionTips":["Verify the case instance is active before mutating its plan items.","Clean up or flag stored ids when a case instance terminates.","Check environment/datasource consistency (test vs prod databases)."],"tags":["cmmn","not-found","entity-lookup"],"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-18T11:17:12.947Z"}