{"record":{"id":"7179d79a024c0c17","repo":"flowable/flowable-engine","slug":"cannot-set-global-variable","errorCode":null,"errorMessage":"Cannot set global variable '","messagePattern":"Cannot set global variable '","errorType":"http","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableBaseResource.java","lineNumber":250,"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 (ScopeTypes.CMMN.equals(task.getScopeType()) && task.getScopeId() != null) {\n                // Explicitly set on execution, setting non-local variable on\n                // task will override local-variable if exists\n                runtimeService.setVariable(task.getScopeId(), 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":232,"sourceCodeEnd":255,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableBaseResource.java#L232-L255","documentation":"FlowableIllegalArgumentException thrown in setVariable when attempting to set a variable with GLOBAL scope on a standalone CMMN task that is not linked to a case (no scopeId). Standalone tasks cannot hold global/process-level variables; only local task variables are allowed. If the task IS part of a case, the variable is set on the case instance via runtimeService.","triggerScenarios":"POST/PUT with scope=global on a standalone task (task.getScopeId() == null) — Flowable falls into the else branch and rejects the operation.","commonSituations":"Clients blanket-applying scope:'global' to all variable calls; migrating REST scripts from process-task usage to standalone task usage; misunderstanding that standalone tasks have no case instance to attach global variables to.","solutions":["Omit the scope field or set scope=local for standalone tasks","Only use scope=global when the task belongs to a case instance","Query the task first to confirm scopeId is set before sending global-scoped variables"],"exampleFix":"// before\n{\"name\":\"v\",\"value\":1,\"scope\":\"global\"}   // standalone task\n// after\n{\"name\":\"v\",\"value\":1,\"scope\":\"local\"}  (or omit scope)","handlingStrategy":"validation","validationCode":"const task = await getTask(taskId);\nif (scope === 'global' && !task.scopeId) throw new Error(`task ${taskId} is standalone; global scope is not allowed`);","typeGuard":"const canSetGlobal = (task) => task != null && typeof task.scopeId === 'string' && task.scopeId.length > 0;","tryCatchPattern":"try { await setVariable({...v, scope:'global'}) } catch (e) { if (/Cannot set global variable/.test(e.message)) return setVariable({...v, scope:'local'}); throw e; }","preventionTips":["Default to scope='local' unless the task belongs to a case instance","Fetch the task first and check scopeId before global writes","Don't blanket-copy scope settings from process-task scripts"],"tags":["rest","cmmn","scope","variables"],"backgroundTag":"invalid-argument-value","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}