{"record":{"id":"47b737a5c01c31c2","repo":"pentaho/pentaho-kettle","slug":"the-function-call-setvariable-requires-3-arguments-47b737","errorCode":null,"errorMessage":"The function call setVariable requires 3 arguments.","messagePattern":"The function call setVariable requires 3 arguments\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1819,"sourceCode":"          inStream.close();\n        }\n      } catch ( Exception Signal ) {\n        // Ignore\n      }\n    }\n  }\n\n  private static Bowl getBowl( Scriptable scope ) {\n    Object scmO = scope.get( \"_step_\", scope );\n    ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );\n    return scm.getTransMeta().getBowl();\n  }\n\n  public static void setVariable( Context actualContext, Scriptable actualObject, Object[] arguments,\n    Function functionContext ) {\n\n    if ( arguments.length != 3 ) {\n      throw Context.reportRuntimeError( \"The function call setVariable requires 3 arguments.\" );\n    }\n\n    Object stepObject = Context.jsToJava( actualObject.get( \"_step_\", actualObject ), StepInterface.class );\n    if ( stepObject instanceof StepInterface ) {\n      StepInterface step = (StepInterface) stepObject;\n      Trans trans = step.getTrans();\n      final String variableName = Context.toString( arguments[ 0 ] );\n      final String variableValue = Context.toString( arguments[ 1 ] );\n      final VariableScope variableScope = getVariableScope( Context.toString( arguments[ 2 ] ) );\n\n      // Set variable in step's scope so that it can be retrieved in the same step using getVariable\n      step.setVariable( variableName, variableValue );\n\n      switch ( variableScope ) {\n        case PARENT:\n          setParentScopeVariable( trans, variableName, variableValue );\n          break;\n        case GRAND_PARENT:","sourceCodeStart":1801,"sourceCodeEnd":1837,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1801-L1837","documentation":"The JavaScript setVariable() function added by Pentaho's ScriptValuesMod step requires exactly 3 arguments: the value, the variable name, and the scope type string. When Rhino invokes the function with any other argument count, the Java implementation throws this Rhino JavaScriptException to abort the script. It exists because setVariable cannot proceed without a value, name, and scope.","triggerScenarios":"Calling setVariable(...) from JS in a Modified Java Script Value step with fewer or more than 3 arguments, e.g. setVariable('myVar') or setVariable('x', 'value', 's', extra).","commonSituations":"Copy-pasted snippets from older Kettle/PDI versions where setVariable had a different signature; forgetting the scope argument; accidentally passing an extra parameter after refactoring.","solutions":["Call setVariable with exactly 3 arguments: value, variableName, and scope ('s','r','p','g').","Check the scope string is one of 's' (system), 'r' (root), 'p' (parent), 'g' (grand-parent).","Verify your script targets the ScriptValuesMod step's documented API, not another scripting engine's setVariable."],"exampleFix":"// before\nsetVariable('MY_VAR');\n// after\nsetVariable('MY_VALUE', 'MY_VAR', 'r');","handlingStrategy":"validation","validationCode":"// in script before calling\nif (arguments.length !== 3) throw new Error('setVariable(value, name, scope) needs exactly 3 args');","typeGuard":null,"tryCatchPattern":"try { setVariable(val, 'MY_VAR', 'r'); } catch (e) { logError('setVariable failed: ' + e.message); }","preventionTips":["Always pass value, name, scope together in one call.","Keep the documented 3-arg signature visible in team script templates.","Lint scripts for setVariable calls with non-3 argument counts."],"tags":["javascript","argument-count","pentaho"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}