{"record":{"id":"9648cedc6ecac5bb","repo":"flowable/flowable-engine","slug":"cannot-set-global-variable-name-on-task-ta","errorCode":null,"errorMessage":"Cannot set global variable '${name}' on task '${task.getId()}', task is not part of process.","messagePattern":"Cannot set global variable '(.+?)' 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/TaskVariableBaseResource.java","lineNumber":249,"sourceCode":"\n        if (restApiInterceptor != null) {\n            if (isNew) {\n                restApiInterceptor.createTaskVariables(task, Collections.singletonMap(name, value), scope);\n            } else {\n                restApiInterceptor.updateTaskVariables(task, Collections.singletonMap(name, value), scope);\n            }\n        }\n\n        if (scope == RestVariableScope.LOCAL) {\n            taskService.setVariableLocal(task.getId(), name, value);\n        } else {\n            if (task.getExecutionId() != null) {\n                // Explicitly set on execution, setting non-local variable on\n                // task will override local-variable if exists\n                runtimeService.setVariable(task.getExecutionId(), name, value);\n            } else {\n                // Standalone task, no global variables possible\n                throw new FlowableIllegalArgumentException(\"Cannot set global variable '\" + name + \"' on task '\" + task.getId() + \"', task is not part of process.\");\n            }\n        }\n    }\n}\n","sourceCodeStart":231,"sourceCodeEnd":254,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableBaseResource.java#L231-L254","documentation":"A standalone task (not linked to a process execution, executionId == null) cannot hold global variables, since global scope means the execution/process scope. Flowable throws FlowableIllegalArgumentException when a global-scope variable is set on such a task.","triggerScenarios":"POST/PUT /runtime/tasks/{taskId}/variables with \"variableScope\": \"global\" on a task created outside any process instance (e.g. via the standalone task REST/TaskService API).","commonSituations":"Standalone tasks created via POST /runtime/tasks; code paths reused between process tasks and standalone tasks; assuming every task belongs to a process; task's process instance already ended so execution link is gone.","solutions":["Use \"variableScope\": \"local\" (or omit scope; defaults to local) for standalone tasks","Attach the task to a process instance if global variables are genuinely needed","Handle the error in clients that accept both process and standalone tasks"],"exampleFix":"// before\n{\"name\": \"priority\", \"value\": 3, \"variableScope\": \"global\"}   // standalone task\n// after\n{\"name\": \"priority\", \"value\": 3, \"variableScope\": \"local\"}","handlingStrategy":"type-guard","validationCode":"const task = await api.get(`/runtime/tasks/${taskId}`); if (!task.data.executionId && scope === 'global') { throw new Error('Standalone task: only local variables allowed'); }","typeGuard":"function canSetGlobal(task) { return Boolean(task && task.executionId); }","tryCatchPattern":"try { await setVariable(taskId, var); } catch (e) { if (isIllegalArgument(e) && /not part of process/.test(e.message)) { await setVariable(taskId, {...var, variableScope: 'local'}); } else { throw e; } }","preventionTips":["Only send variableScope=global for tasks with an executionId","Default to local scope when uncertain","Branch on standalone vs process tasks in client code"],"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"}