{"record":{"id":"ad7bde96c1e6e96b","repo":"flowable/flowable-engine","slug":"cannot-set-global-variables-on-execution-execut","errorCode":null,"errorMessage":"Cannot set global variables on execution '${executionId}', task is not part of process.","messagePattern":"Cannot set global variables on execution '(.+?)', task is not part of process\\.","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/process/BaseVariableCollectionResource.java","lineNumber":167,"sourceCode":"                        runtimeService.setVariablesLocal(execution.getId(), variablesToSet);\n                        setVariables = runtimeService.getVariablesLocal(execution.getId(), variablesToSet.keySet());\n                    }\n                    \n                } else {\n                    if (execution.getParentId() != null) {\n                        // Explicitly set on parent, setting non-local variables on execution itself will override local-variables if exists\n                        \n                        if (async) {\n                            runtimeService.setVariablesAsync(execution.getParentId(), variablesToSet);\n                            \n                        } else {\n                            runtimeService.setVariables(execution.getParentId(), variablesToSet);\n                            setVariables = runtimeService.getVariables(execution.getParentId(), variablesToSet.keySet());\n                        }\n                        \n                    } else {\n                        // Standalone task, no global variables possible\n                        throw new FlowableIllegalArgumentException(\"Cannot set global variables on execution '\" + execution.getId() + \"', task is not part of process.\");\n                    }\n                }\n\n                if (!async) {\n                    for (RestVariable inputVariable : inputVariables) {\n                        String variableName = inputVariable.getName();\n                        Object variableValue = setVariables.get(variableName);\n                        resultVariables.add(restResponseFactory.createRestVariable(variableName, variableValue, varScope, execution.getId(), variableType, false));\n                    }\n                }\n\n            }\n        }\n        response.setStatus(HttpStatus.CREATED.value());\n        return result;\n    }\n\n    protected void addGlobalVariables(Execution execution, Map<String, RestVariable> variableMap) {","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/process/BaseVariableCollectionResource.java#L149-L185","documentation":"FlowableIllegalArgumentException thrown when a standalone task (not linked to any process execution) is asked to set 'global' (process-level) variables. Global variables require a parent process execution; a task without one has nowhere to store them.","triggerScenarios":"POST/PUT to /runtime/tasks/{taskId}/variables with scope=global where the task is standalone (created via the task service, not part of a process instance), so execution.getParentId() is null.","commonSituations":"Client code reuses a variable-update routine for both process and standalone tasks; task created via the tasks REST API then erroneously given process-level variables; process association removed/never established.","solutions":["Use scope=local in the request body so the variables are stored on the task itself.","If process-global variables are intended, verify the task actually belongs to a process instance (GET /runtime/tasks/{id} and check processInstanceId).","Route standalone-task variable writes to the task-scoped endpoint instead of the global-variable code path.","Catch FlowableIllegalArgumentException (HTTP 400) and fall back to local-scope storage."],"exampleFix":"// before\nPOST /runtime/tasks/{taskId}/variables\n{\"scope\":\"global\",\"name\":\"orderId\",\"value\":\"42\"}\n// after\nPOST /runtime/tasks/{taskId}/variables\n{\"scope\":\"local\",\"name\":\"orderId\",\"value\":\"42\"}","handlingStrategy":"validation","validationCode":"const task = await fetch(`/runtime/tasks/${taskId}`).then(r => r.json());\nif (scope === 'global' && !task.processInstanceId) throw new Error('Standalone task: global variables not allowed');","typeGuard":null,"tryCatchPattern":"try { /* set task variables */ } catch (e) {\n  if (e.status === 400 && /task is not part of process/.test(e.message)) {\n    // fall back to scope=local\n  } else throw e;\n}","preventionTips":["Default task variables to scope=local unless you know the task belongs to a process","Check processInstanceId on the task resource before global-scope writes","Keep one variable-writing helper that branches on task.parentTaskId/processInstanceId"],"tags":["rest-api","variables","tasks","flowable"],"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-18T11:17:12.947Z"}