flowable/flowable-engine · error · FlowableIllegalArgumentException

Cannot set global variables on task

Error message

Cannot set global variables on task '${taskId}', task is not part of process.

What it means

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.

Solutions

  1. Use variableScope LOCAL for variables on standalone tasks
  2. Verify the task belongs to a case instance before requesting global scope
  3. Create the task within a case if case-level variables are actually needed
  4. Remove the variableScope field so it defaults to LOCAL

Example fix

// before
POST /cmmn-runtime/tasks/standalone-task/variables  [{"name":"x","value":1,"variableScope":"global"}]
// after
POST /cmmn-runtime/tasks/standalone-task/variables  [{"name":"x","value":1,"variableScope":"local"}]
Defensive patterns

Strategy: validation

Validate before calling

const task = (await api.get(`/tasks/${taskId}`)).data;
const wantsGlobal = variables.some(v => (v.variableScope ?? 'local').toLowerCase() !== 'local');
if (wantsGlobal && (task.scopeId == null || task.scopeType == null)) throw new Error('Standalone task: only LOCAL variables are allowed');

Try / catch

try { await api.post(`/tasks/${taskId}/variables`, body); }
catch (e) { if (/global variables.*not part of/i.test(e.message)) demoteToLocalAndRetry(body); else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/5f1f8df9946ef210. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-cmmn-rest/src/main/java/org/flowable/cmmn/rest/service/api/runtime/task/TaskVariableCollectionResource.java:199

            if (!variablesToSet.isEmpty()) {
                if (restApiInterceptor != null) {
                    restApiInterceptor.createTaskVariables(task, variablesToSet, sharedScope);
                }

                Map<String, Object> setVariables;
                if (sharedScope == RestVariableScope.LOCAL) {
                    taskService.setVariablesLocal(task.getId(), variablesToSet);
                    setVariables = taskService.getVariablesLocal(task.getId(), variablesToSet.keySet());
                } else {
                    if (task.getScopeId() != null) {
                        // Explicitly set on case, setting non-local
                        // variables on task will override local-variables if exists
                        runtimeService.setVariables(task.getScopeId(), variablesToSet);
                        setVariables = runtimeService.getVariables(task.getScopeId(), variablesToSet.keySet());
                    } else {
                        // Standalone task, no global variables possible
                        throw new FlowableIllegalArgumentException("Cannot set global variables on task '" + task.getId() + "', task is not part of process.");
                    }
                }

                for (RestVariable inputVariable : inputVariables) {
                    String variableName = inputVariable.getName();
                    Object variableValue = setVariables.get(variableName);
                    resultVariables.add(restResponseFactory.createRestVariable(variableName, variableValue, varScope, task.getId(), CmmnRestResponseFactory.VARIABLE_TASK, false));
                }
            }
        }

        return result;
    }

    @ApiOperation(value = "Delete all local variables on a task", tags = { "Tasks" }, code = 204)
    @ApiResponses(value = {
            @ApiResponse(code = 204, message = "Indicates all local task variables have been deleted. Response-body is intentionally empty."),
            @ApiResponse(code = 404, message = "Indicates the requested task was not found.")

View on GitHub (pinned to d6d39ce1c6)