{"record":{"id":"912b4df1be0225bc","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getvariable-requires-2-arguments-912b4d","errorCode":null,"errorMessage":"The function call getVariable requires 2 arguments.","messagePattern":"The function call getVariable requires 2 arguments\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1939,"sourceCode":"        Object scmo = actualObject.get( \"_step_\", actualObject );\n        Object scmO = Context.jsToJava( scmo, StepInterface.class );\n\n        if ( scmO instanceof StepInterface ) {\n          StepInterface scm = (StepInterface) Context.jsToJava( scmO, StepInterface.class );\n\n          sArg1 = Context.toString( ArgList[0] );\n          sArg2 = Context.toString( ArgList[1] );\n          return scm.getVariable( sArg1, sArg2 );\n        } else {\n          // running via the Test button in a dialog\n          sArg2 = Context.toString( ArgList[1] );\n          return sArg2;\n        }\n      } catch ( Exception e ) {\n        sRC = \"\";\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call getVariable requires 2 arguments.\" );\n    }\n    return sRC;\n  }\n\n  // Return the output row metadata\n  public static RowMetaInterface getOutputRowMeta( Context actualContext, Scriptable actualObject,\n    Object[] ArgList, Function FunctionContext ) {\n    if ( ArgList.length == 0 ) {\n      try {\n        Object scmO = actualObject.get( \"_step_\", actualObject );\n        try {\n          ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );\n          return scm.getOutputRowMeta();\n        } catch ( Exception e ) {\n          ScriptValuesModDummy scm = (ScriptValuesModDummy) Context.jsToJava( scmO, ScriptValuesModDummy.class );\n          return scm.getOutputRowMeta();\n        }\n      } catch ( Exception e ) {","sourceCodeStart":1921,"sourceCodeEnd":1957,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1921-L1957","documentation":"The JS getVariable() function requires exactly 2 arguments: the variable name and the scope type string. If the argument count differs, the implementation throws this Rhino runtime error instead of returning a value. The two-part signature lets getVariable know both what to read and from which scope.","triggerScenarios":"getVariable('MY_VAR') with no scope argument, or getVariable('A','r','extra') with an extra argument, in a Modified Java Script Value step.","commonSituations":"Porting scripts from JavaScript engines where getVariable took one argument; forgetting the scope letter; calling with zero arguments when the variable name was built dynamically.","solutions":["Call getVariable with exactly 2 arguments: variable name and scope ('s','r','p','g').","If the variable may be missing, wrap the call or supply a default in your script.","Confirm you are not conflating getVariable with Java-side getVariable methods."],"exampleFix":"// before\nvar v = getVariable('MY_VAR');\n// after\nvar v = getVariable('MY_VAR', 'r');","handlingStrategy":"validation","validationCode":"if (arguments.length !== 2) throw new Error('getVariable(name, scope) needs exactly 2 args');","typeGuard":null,"tryCatchPattern":"try { v = getVariable(name, 'r'); } catch (e) { v = defaultValue; }","preventionTips":["Always supply the scope letter as the second argument.","Wrap getVariable in a helper that provides a default value.","Review one-argument getVariable calls when porting old scripts."],"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"}