{"record":{"id":"94d89ab88a7ad0a8","repo":"flowable/flowable-engine","slug":"variable-name-is-already-present-on-task-t","errorCode":null,"errorMessage":"Variable '${name}' is already present on task '${taskId}'.","messagePattern":"Variable '(.+?)' is already present on task '(.+?)'\\.","errorType":"http","errorClass":"FlowableConflictException","httpStatus":409,"severity":"error","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableCollectionResource.java","lineNumber":175,"sourceCode":"            for (RestVariable var : inputVariables) {\n                // Validate if scopes match\n                varScope = var.getVariableScope();\n                if (var.getName() == null) {\n                    throw new FlowableIllegalArgumentException(\"Variable name is required\");\n                }\n\n                if (varScope == null) {\n                    varScope = RestVariableScope.LOCAL;\n                }\n                if (sharedScope == null) {\n                    sharedScope = varScope;\n                }\n                if (varScope != sharedScope) {\n                    throw new FlowableIllegalArgumentException(\"Only allowed to update multiple variables in the same scope.\");\n                }\n\n                if (hasVariableOnScope(task, var.getName(), varScope)) {\n                    throw new FlowableConflictException(\"Variable '\" + var.getName() + \"' is already present on task '\" + task.getId() + \"'.\");\n                }\n\n                Object actualVariableValue = restResponseFactory.getVariableValue(var);\n                variablesToSet.put(var.getName(), actualVariableValue);\n            }\n\n            if (!variablesToSet.isEmpty()) {\n                if (restApiInterceptor != null) {\n                    restApiInterceptor.createTaskVariables(task, variablesToSet, sharedScope);\n                }\n\n                Map<String, Object> setVariables;\n                if (sharedScope == RestVariableScope.LOCAL) {\n                    taskService.setVariablesLocal(task.getId(), variablesToSet);\n                    setVariables = taskService.getVariablesLocal(task.getId(), variablesToSet.keySet());\n                } else {\n                    if (task.getScopeId() != null) {\n                        // Explicitly set on case, setting non-local","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableCollectionResource.java#L157-L193","documentation":"FlowableConflictException thrown by createTaskVariable when a variable with the same name already exists on the task in the target scope. The collection-create endpoint only adds new variables; it refuses to silently overwrite existing ones. The client must delete the variable first or use the update (PUT) endpoint.","triggerScenarios":"POST /cmmn-runtime/tasks/{taskId}/variables with a body containing a variable whose name is already set on the task in the same scope, as checked by hasVariableOnScope.","commonSituations":"Replaying a create request after a partial failure; scripts that add variables on retry; clients that should be calling PUT /variables/{variableName} instead of POST.","solutions":["Use PUT /cmmn-runtime/tasks/{taskId}/variables/{name} to overwrite an existing variable","DELETE the existing variable before POSTing it again","Skip names already present (query GET /variables first)","Use a different variable name if a new variable is intended"],"exampleFix":"// before\nPOST /cmmn-runtime/tasks/123/variables  [{\"name\":\"status\",\"value\":\"done\"}]\n// after\nPUT /cmmn-runtime/tasks/123/variables/status  {\"name\":\"status\",\"value\":\"done\"}","handlingStrategy":"validation","validationCode":"const existing = (await api.get(`/tasks/${taskId}/variables`)).data.map(v => v.name);\nconst dupes = variables.filter(v => existing.includes(v.name));\nif (dupes.length) throw new Error(`Variables already present: ${dupes.map(d => d.name).join(', ')}`);","typeGuard":null,"tryCatchPattern":"try { await api.post(`/tasks/${taskId}/variables`, body); }\ncatch (e) { if (e.status === 409) await putUpdateInstead(body); else throw e; }","preventionTips":["GET existing variables before POSTing","Prefer PUT for idempotent set semantics","Make create scripts skip already-present names"],"tags":["rest","conflict","duplicate"],"backgroundTag":"file-already-exists","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"}