{"record":{"id":"48b34243b0049ac5","repo":"pentaho/pentaho-kettle","slug":"the-argument-type-of-function-call-setvariable-should-either-48b342","errorCode":null,"errorMessage":"The argument type of function call setVariable should either be \"s\", \"r\", \"p\", or \"g\".","messagePattern":"The argument type of function call setVariable should either be \"s\", \"r\", \"p\", or \"g\"\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1908,"sourceCode":"      if ( grandParentSpace != null ) {\n        grandParentSpace.setVariable( variableName, variableValue );\n      }\n    }\n  }\n\n\n  static VariableScope getVariableScope( String codeOfScope ) {\n    switch ( codeOfScope ) {\n      case \"s\":\n        return VariableScope.SYSTEM;\n      case \"r\":\n        return VariableScope.ROOT;\n      case \"p\":\n        return VariableScope.PARENT;\n      case \"g\":\n        return VariableScope.GRAND_PARENT;\n      default:\n        throw Context.reportRuntimeError( \"The argument type of function call \"\n          + \"setVariable should either be \\\"s\\\", \\\"r\\\", \\\"p\\\", or \\\"g\\\".\" );\n    }\n  }\n\n  // Returning EnvironmentVar\n  public static String getVariable( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    String sRC = \"\";\n    String sArg1 = \"\";\n    String sArg2 = \"\";\n    if ( ArgList.length == 2 ) {\n      try {\n        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","sourceCodeStart":1890,"sourceCodeEnd":1926,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1890-L1926","documentation":"setVariable()'s third argument selects the variable scope and must be one of 's' (system), 'r' (root), 'p' (parent), or 'g' (grand-parent). The implementation maps the string via a switch whose default branch throws this Rhino runtime error for any unrecognized scope. It prevents silently writing variables into an unintended scope.","triggerScenarios":"setVariable(value, 'MY_VAR', 'X') or setVariable(value, name, null) or an empty-string scope — any third argument other than 's','r','p','g'.","commonSituations":"Typos like 'S' or 'root'; passing a numeric scope constant from another framework; localization mistakes; forgetting the scope is a single lowercase letter.","solutions":["Use one of the four accepted scope strings: 's', 'r', 'p', or 'g' (lowercase).","Pass VariableScope-appropriate scope: 's' system, 'r' root, 'p' parent transformation, 'g' grand-parent.","Guard the scope in script before calling setVariable."],"exampleFix":"// before\nsetVariable(val, 'MY_VAR', 'system');\n// after\nsetVariable(val, 'MY_VAR', 's');","handlingStrategy":"validation","validationCode":"var scope = 'r';\nif (['s','r','p','g'].indexOf(scope) === -1) throw new Error('invalid scope ' + scope);","typeGuard":null,"tryCatchPattern":"try { setVariable(val, name, scope); } catch (e) { if (String(e).indexOf('argument type') >= 0) setVariable(val, name, 'r'); else throw e; }","preventionTips":["Memorize the four scope letters: s, r, p, g — always lowercase.","Centralize scope strings as constants in shared script snippets.","Never pass scope constants from other frameworks."],"tags":["javascript","invalid-argument","scope","pentaho"],"backgroundTag":"invalid-enum-value","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"}