{"record":{"id":"31670ebfab4981e1","repo":"flowable/flowable-engine","slug":"is-created-by-the-process-engine-and-should-be-co-31670e","errorCode":null,"errorMessage":" is created by the process engine and should be completed via the process engine API","messagePattern":" is created by the process engine and should be completed via the process engine API","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CompleteTaskWithFormCmd.java","lineNumber":113,"sourceCode":"    public CompleteTaskWithFormCmd(String taskId, String formDefinitionId, String outcome, Map<String,\n            Object> variables, Map<String, Object> variablesLocal, Map<String, Object> transientVariables, Map<String, Object> transientVariablesLocal) {\n        this(taskId, formDefinitionId, outcome, variables, transientVariables);\n        this.variablesLocal = variablesLocal;\n        this.transientVariablesLocal = transientVariablesLocal;\n    }\n    \n    public CompleteTaskWithFormCmd(String taskId, String formDefinitionId, String outcome, String userId,\n            Map<String,Object> variables, Map<String, Object> variablesLocal, Map<String, Object> transientVariables, \n            Map<String, Object> transientVariablesLocal) {\n        \n        this(taskId, formDefinitionId, outcome, variables, variablesLocal, transientVariables, transientVariablesLocal);\n        this.userId = userId;\n    }\n\n    @Override\n    protected Void execute(CommandContext commandContext, TaskEntity task) {\n        if (StringUtils.isNotEmpty(task.getProcessInstanceId())) {\n            throw new FlowableException(task + \" is created by the process engine and should be completed via the process engine API\");\n        }\n        \n        FormService formService = CommandContextUtil.getFormService(commandContext);\n        if (formService == null) {\n            throw new FlowableIllegalArgumentException(\"Form engine is not initialized\");\n        }\n\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        FormRepositoryService formRepositoryService = CommandContextUtil.getFormRepositoryService(commandContext);\n        FormInfo formInfo = formRepositoryService.getFormModelById(formDefinitionId);\n\n        if (formInfo != null) {\n            // validate input at first\n            FormFieldHandler formFieldHandler = cmmnEngineConfiguration.getFormFieldHandler();\n            if (isFormFieldValidationEnabled(task)) {\n                formService.validateFormFields(task.getTaskDefinitionKey(), \"humanTask\", task.getScopeId(), \n                        task.getScopeDefinitionId(), ScopeTypes.CMMN, formInfo, variables);\n            }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CompleteTaskWithFormCmd.java#L95-L131","documentation":"Thrown by CompleteTaskWithFormCmd when the task being completed with a form has a non-empty processInstanceId, i.e. it was created by the BPMN process engine. As with plain completeTask, the CMMN engine refuses to complete a task it does not own; form-based completion must go through the engine that created the task.","triggerScenarios":"Calling CmmnTaskService.completeTaskWithForm(taskId, ...) on a task whose getProcessInstanceId() is not empty (a BPMN process user task).","commonSituations":"Generic task inbox completing both process and case tasks via the CMMN form API; migration from BPMN-only to CMMN code paths where task routing was not updated.","solutions":["Check task.getProcessInstanceId() before form completion and route process tasks to the BPMN completeTaskWithForm/TaskService API.","Split task queries by processInstanceId vs caseInstanceId so each engine handles its own tasks.","Refactor the task inbox to hold a reference to the originating engine per task."],"exampleFix":"// before\ncmmnTaskService.completeTaskWithForm(taskId, formDefinitionId, outcome, variables);\n// after\nif (task.getProcessInstanceId() != null) {\n    processTaskService.completeTaskWithForm(taskId, formDefinitionId, outcome, variables);\n} else {\n    cmmnTaskService.completeTaskWithForm(taskId, formDefinitionId, outcome, variables);\n}","handlingStrategy":"validation","validationCode":"org.flowable.task.api.Task t = taskService.createTaskQuery().taskId(taskId).singleResult();\nif (t != null && t.getProcessInstanceId() != null) {\n    processTaskService.completeTaskWithForm(taskId, formDefinitionId, outcome, variables);\n} else {\n    cmmnTaskService.completeTaskWithForm(taskId, formDefinitionId, outcome, variables);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track each task's source engine in your task inbox model.","Never mix CMMN form completion with BPMN-created tasks."],"tags":["cmmn","wrong-engine","form-completion","flowable"],"backgroundTag":"unsupported-operation","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"}