{"record":{"id":"626d3501d9af3d71","repo":"flowable/flowable-engine","slug":"cannot-set-global-variables-on-task-task-getid","errorCode":null,"errorMessage":"Cannot set global variables on task '${task.getId()}', 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-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableCollectionResource.java","lineNumber":199,"sourceCode":"            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.getExecutionId() != null) {\n                        // Explicitly set on execution, setting non-local\n                        // variables on task will override local-variables if\n                        // exists\n                        runtimeService.setVariables(task.getExecutionId(), variablesToSet);\n                        setVariables = runtimeService.getVariables(task.getExecutionId(), 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(), RestResponseFactory.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-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableCollectionResource.java#L181-L217","documentation":"Like single-variable creation, the bulk endpoint cannot set global-scope variables on a standalone task: with a null executionId there is no process scope to hold them, so FlowableIllegalArgumentException is thrown.","triggerScenarios":"POST /runtime/tasks/{taskId}/variables with sharedScope=global (any/all entries global) on a task whose executionId is null (standalone task, or process already terminated).","commonSituations":"Standalone tasks created via the REST API; batches grouped into a global scope by one stray entry; code paths shared between process and standalone tasks.","solutions":["Use \"variableScope\": \"local\" for all entries on standalone tasks","Split the request so global variables go to the execution/process endpoints instead","Guard: check the task is part of a process before sending global-scope batches"],"exampleFix":"// before\n[{\"name\":\"a\",\"value\":1,\"variableScope\":\"global\"}]  // standalone task\n// after\n[{\"name\":\"a\",\"value\":1,\"variableScope\":\"local\"}]","handlingStrategy":"type-guard","validationCode":"const task = await api.get(`/runtime/tasks/${taskId}`); if (!task.data.executionId && variables.some(v => (v.variableScope || 'local') === 'global')) { throw new Error('Global variables not allowed on standalone task'); }","typeGuard":"function batchAllowed(task, vars) { return Boolean(task.executionId) || !vars.some(v => (v.variableScope || 'local') === 'global'); }","tryCatchPattern":"try { await api.post(`/runtime/tasks/${taskId}/variables`, vars); } catch (e) { if (e.response && e.response.status === 400 && /global variables/.test(e.response.data.message || '')) { await api.post(`/runtime/tasks/${taskId}/variables`, vars.map(v => ({...v, variableScope: 'local'}))); } else { throw e; } }","preventionTips":["Check executionId before sending global-scope batches","Keep standalone-task payloads local-only","Route global variables to process/execution endpoints instead"],"tags":["rest-api","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"}