{"record":{"id":"faea0d38bf5c4501","repo":"pentaho/pentaho-kettle","slug":"the-function-call-decode-requires-more-than-1-argument-faea0d","errorCode":null,"errorMessage":"The function call decode requires more than 1 argument.","messagePattern":"The function call decode requires more than 1 argument\\.","errorType":"exception","errorClass":"RhinoRuntimeError","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":1534,"sourceCode":"      if ( ArgList.length >= 2 ) {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return Context.getUndefinedValue();\n        }\n        Object objToCompare = ArgList[0];\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          if ( ArgList[i].equals( objToCompare ) ) {\n            return ArgList[i + 1];\n          }\n        }\n        if ( ArgList.length % 2 == 0 ) {\n          return ArgList[ArgList.length - 1];\n        } else {\n          return objToCompare;\n        }\n      } else {\n        throw Context.reportRuntimeError( \"The function call decode requires more than 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( \"The function call decode is not valid : \" + e.getMessage() );\n    }\n  }\n\n  public static String replace( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return (String) Context.getUndefinedValue();\n        }\n        String objForReplace = Context.toString( ArgList[0] );\n        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {\n          objForReplace =","sourceCodeStart":1516,"sourceCodeEnd":1552,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L1516-L1552","documentation":"The Pentaho Kettle ScriptValuesMod JavaScript function `decode(expr, search1, result1, ... [, default])` requires more than 1 argument (at minimum the expression plus one search/result pair or a default). The function throws this Rhino runtime error when `ArgList.length <= 1`, mirroring the Oracle SQL DECODE contract.","triggerScenarios":"Calling `decode()` with zero arguments, or exactly one argument (e.g. `decode(myField)`), instead of the required `decode(value, search, result, ...)` form.","commonSituations":"Developers translating SQL DECODE into a Modified Java/JavaScript step forget the extra arguments; a field whose name resolves to nothing is sometimes mistaken for a valid single-arg call; typo'd variable leaves only the first argument.","solutions":["Call decode with at least 3 arguments: decode(expr, search1, result1, [, search2, result2, ...] [, default])","If you intended a simple null/empty check, use plain JavaScript instead of decode","Verify the field referenced in the first argument exists in the row and is passed correctly"],"exampleFix":"// before\nvar out = decode(value);\n// after\nvar out = decode(value, 'Y', 1, 'N', 0, -1);","handlingStrategy":"validation","validationCode":"if (typeof value === 'undefined' || value === null || arguments.length < 3) {\n  throw new Error('decode requires (expr, search, result[, ...default])');\n}\nvar out = decode(value, 'Y', 1, 'N', 0, -1);","typeGuard":"function isDecodeSafe(args) { return Array.isArray(args) && args.length >= 3; }","tryCatchPattern":null,"preventionTips":["Always supply a default argument as the last decode parameter","Count arguments: decode needs at least 3 (expr, search, result)","Check for null row fields before invoking decode"],"tags":["javascript","pentaho","scripting","argument-count"],"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"}