{"record":{"id":"5f1f8df9946ef210","repo":"flowable/flowable-engine","slug":"cannot-set-global-variables-on-task-taskid-t","errorCode":null,"errorMessage":"Cannot set global variables on task '${taskId}', task is not part of process.","messagePattern":"Cannot set global variables on task '(.+?)', task is not part of process\\.","errorType":"http","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableCollectionResource.java","lineNumber":199,"sourceCode":"\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\n                        // variables on task will override local-variables if exists\n                        runtimeService.setVariables(task.getScopeId(), variablesToSet);\n                        setVariables = runtimeService.getVariables(task.getScopeId(), variablesToSet.keySet());\n                    } else {\n                        // Standalone task, no global variables possible\n                        throw new FlowableIllegalArgumentException(\"Cannot set global variables on task '\" + task.getId() + \"', task is not part of process.\");\n                    }\n                }\n\n                for (RestVariable inputVariable : inputVariables) {\n                    String variableName = inputVariable.getName();\n                    Object variableValue = setVariables.get(variableName);\n                    resultVariables.add(restResponseFactory.createRestVariable(variableName, variableValue, varScope, task.getId(), CmmnRestResponseFactory.VARIABLE_TASK, false));\n                }\n            }\n        }\n\n        return result;\n    }\n\n    @ApiOperation(value = \"Delete all local variables on a task\", tags = { \"Tasks\" }, code = 204)\n    @ApiResponses(value = {\n            @ApiResponse(code = 204, message = \"Indicates all local task variables have been deleted. Response-body is intentionally empty.\"),\n            @ApiResponse(code = 404, message = \"Indicates the requested task was not found.\")","sourceCodeStart":181,"sourceCodeEnd":217,"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#L181-L217","documentation":"FlowableIllegalArgumentException thrown by createTaskVariable when a standalone CMMN task (not part of a case/process scope) receives variables with a non-LOCAL scope. Global (case-level) variables only exist when the task belongs to a scope such as a case instance; a standalone task has nowhere to store them.","triggerScenarios":"POST /cmmn-runtime/tasks/{taskId}/variables targeting a standalone task with variables whose variableScope is GLOBAL/CASE, hitting the branch where task.getScopeId() is null.","commonSituations":"Setting scope \"global\" on tasks created outside any case definition; clients that always send variableScope=global regardless of task type; migration scripts assuming every task is case-scoped.","solutions":["Use variableScope LOCAL for variables on standalone tasks","Verify the task belongs to a case instance before requesting global scope","Create the task within a case if case-level variables are actually needed","Remove the variableScope field so it defaults to LOCAL"],"exampleFix":"// before\nPOST /cmmn-runtime/tasks/standalone-task/variables  [{\"name\":\"x\",\"value\":1,\"variableScope\":\"global\"}]\n// after\nPOST /cmmn-runtime/tasks/standalone-task/variables  [{\"name\":\"x\",\"value\":1,\"variableScope\":\"local\"}]","handlingStrategy":"validation","validationCode":"const task = (await api.get(`/tasks/${taskId}`)).data;\nconst wantsGlobal = variables.some(v => (v.variableScope ?? 'local').toLowerCase() !== 'local');\nif (wantsGlobal && (task.scopeId == null || task.scopeType == null)) throw new Error('Standalone task: only LOCAL variables are allowed');","typeGuard":null,"tryCatchPattern":"try { await api.post(`/tasks/${taskId}/variables`, body); }\ncatch (e) { if (/global variables.*not part of/i.test(e.message)) demoteToLocalAndRetry(body); else throw e; }","preventionTips":["Check task.scopeId/scopeType before using global scope","Default to LOCAL scope for standalone tasks","Only use GLOBAL scope on case-scoped tasks"],"tags":["rest","scope","standalone-task"],"backgroundTag":"unsupported-operation","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"}