{"record":{"id":"43bc7816371bad9e","repo":"flowable/flowable-engine","slug":"activityinstance-not-found-for","errorCode":null,"errorMessage":"ActivityInstance not found for ","messagePattern":"ActivityInstance not found for ","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/HistoricDetailEntityManagerImpl.java","lineNumber":59,"sourceCode":"\n    @Override\n    public HistoricFormPropertyEntity insertHistoricFormPropertyEntity(ExecutionEntity execution,\n        String propertyId, String propertyValue, String taskId, Date createTime) {\n\n        HistoricFormPropertyEntity historicFormPropertyEntity = dataManager.createHistoricFormProperty();\n        historicFormPropertyEntity.setProcessInstanceId(execution.getProcessInstanceId());\n        historicFormPropertyEntity.setExecutionId(execution.getId());\n        historicFormPropertyEntity.setTaskId(taskId);\n        historicFormPropertyEntity.setPropertyId(propertyId);\n        historicFormPropertyEntity.setPropertyValue(propertyValue);\n        historicFormPropertyEntity.setTime(createTime);\n\n        ActivityInstanceEntity activityInstance = getActivityInstanceEntityManager().findUnfinishedActivityInstance(execution);\n        String activityInstanceId;\n        if (activityInstance != null) {\n            activityInstanceId = activityInstance.getId();\n        } else {\n            throw new FlowableException(\"ActivityInstance not found for \" + execution);\n        }\n        historicFormPropertyEntity.setActivityInstanceId(activityInstanceId);\n\n        insert(historicFormPropertyEntity);\n        return historicFormPropertyEntity;\n    }\n\n    @Override\n    public HistoricDetailVariableInstanceUpdateEntity copyAndInsertHistoricDetailVariableInstanceUpdateEntity(VariableInstanceEntity variableInstance,\n        Date createTime) {\n        HistoricDetailVariableInstanceUpdateEntity historicVariableUpdate = dataManager.createHistoricDetailVariableInstanceUpdate();\n        historicVariableUpdate.setProcessInstanceId(variableInstance.getProcessInstanceId());\n        historicVariableUpdate.setExecutionId(variableInstance.getExecutionId());\n        historicVariableUpdate.setTaskId(variableInstance.getTaskId());\n        historicVariableUpdate.setTime(createTime);\n        historicVariableUpdate.setRevision(variableInstance.getRevision());\n        historicVariableUpdate.setName(variableInstance.getName());\n        historicVariableUpdate.setVariableType(variableInstance.getType());","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/persistence/entity/HistoricDetailEntityManagerImpl.java#L41-L77","documentation":"Thrown when inserting a historic form property and no unfinished activity instance can be resolved for the execution. Flowable requires an activityInstanceId to attach the historic form property record to, so if the ActivityInstanceManager cannot find one for the given ExecutionEntity, it aborts. This indicates the execution has no currently open/unrecorded activity, usually because historic activity instance tracking is out of sync or the execution is not inside a real activity.","triggerScenarios":"Calling HistoricDataService / form-property recording (historyLevel FORM) via insertHistoricFormPropertyEntity when execution has no matching unfinished ActivityInstanceEntity — e.g. recording form properties for an execution not positioned at an activity, custom code invoking historic detail insertion manually, or history/activity-instance data deleted or not created due to history level misconfiguration.","commonSituations":"Running with a history level below ACTIVITY so activity instances are never recorded while form property history is attempted; custom jobs or migration scripts copying executions without their activity instances; database cleanup jobs deleting ACT_HI_ACTINST rows for running instances; using an execution obtained outside the normal activity scope.","solutions":["Ensure the process engine history level is ACTIVITY or higher (flowable.history-level / historyLevel config) so activity instances are created before form properties are recorded.","Verify the execution passed is an active execution currently positioned at an activity; do not call historic form-property insertion manually for arbitrary executions.","Check ACT_HI_ACTINST for the process instance; if rows are missing, restore from backup or restart the instance rather than continuing.","If you only need form data history, store it as process/task variables with history enabled instead of calling the historic detail API directly."],"exampleFix":"// before\nhistoryService.createHistoricDetailQuery()... // relies on form property history\n// config after\n// flowable.cfg.xml\n<property name=\"historyLevel\" value=\"ACTIVITY\" /> <!-- or FULL -->","handlingStrategy":"validation","validationCode":"boolean active = runtimeService.createExecutionQuery().processInstanceId(pid).activityId(activityId).count() > 0;\nif (!active) throw new IllegalStateException(\"No active execution/activity to record form property for\");","typeGuard":null,"tryCatchPattern":"try { ... } catch (FlowableException e) { if (e.getMessage().startsWith(\"ActivityInstance not found\")) { /* skip history recording or raise history level */ } else throw e; }","preventionTips":["Keep history level at ACTIVITY or FULL when form property history is needed","Never delete ACT_HI_ACTINST rows for still-running instances","Don't invoke historic detail insertion manually for arbitrary executions"],"tags":["history","activity-instance","persistence"],"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"}