{"record":{"id":"c09eb262e9be5e79","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getdigitsonly-requires-1-argument","errorCode":null,"errorMessage":"The function call getDigitsOnly requires 1 argument.","messagePattern":"The function call getDigitsOnly requires 1 argument\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":110,"sourceCode":"    \"createRowCopy\", \"putRow\", \"deleteFile\", \"createFolder\", \"copyFile\", \"getFileSize\", \"isFile\", \"isFolder\",\n    \"getShortFilename\", \"getFileExtension\", \"getParentFoldername\", \"getLastModifiedTime\", \"trunc\", \"truncDate\",\n    \"moveFile\", };\n\n  // This is only used for reading, so no concurrency problems.\n  // todo: move in the real variables of the step.\n  // private static VariableSpace variables = Variables.getADefaultVariableSpace();\n\n  // Functions to Add\n  // date2num, num2date,\n  // fisc_date, isNull\n  //\n\n  public static String getDigitsOnly( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    if ( ArgList.length == 1 ) {\n      return Const.getDigitsOnly( (String) ArgList[0] ); // TODO AKRETION ensure\n    } else {\n      throw new RuntimeException( \"The function call getDigitsOnly requires 1 argument.\" );\n\n    }\n  }\n\n  public static boolean LuhnCheck( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n\n    boolean returnCode = false;\n\n    if ( ArgList.length == 1 ) {\n      if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {\n        try {\n          int sum = 0;\n          int digit = 0;\n          int addend = 0;\n          boolean timesTwo = false;\n          String argstring = (String) ArgList[0];\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L92-L128","documentation":"The Script step's added JS function getDigitsOnly is a thin wrapper over Const.getDigitsOnly(String) and accepts exactly one argument: the input string. When the script calls it with any other arity, it throws RuntimeException instead of silently coercing.","triggerScenarios":"Calling getDigitsOnly() with zero arguments, or with 2+ arguments (e.g. getDigitsOnly(str, someFlag)), from JavaScript inside the Script step.","commonSituations":"Porting scripts from JavaScript's String.replace habit and passing a regex/flag; copy-paste from other dialects where a second locale/charset arg was used; typos adding an extra comma.","solutions":["Call getDigitsOnly with exactly one string argument","Strip extra logic out of the call; filter digits afterwards in JS if needed","Wrap the call in a JS try/catch if argument count is dynamic"],"exampleFix":"// before\nvar digits = getDigitsOnly(phoneNumber, true);\n// after\nvar digits = getDigitsOnly(phoneNumber);","handlingStrategy":"validation","validationCode":"// JS in Script step\nif (arguments.length !== 1 || typeof arguments[0] !== 'string') {\n  throw new Error('getDigitsOnly expects exactly one string argument');\n}\nvar digits = getDigitsOnly(str);","typeGuard":"// JS\nfunction isSingleString(args) {\n  return args.length === 1 && typeof args[0] === 'string';\n}","tryCatchPattern":"try {\n  var digits = getDigitsOnly(str);\n} catch (e) {\n  Logger.logError('getDigitsOnly failed: ' + e.message);\n  digits = null;\n}","preventionTips":["Check the function's documented arity in the Script step help before use","Keep one-argument-per-line style to spot stray commas","Unit-test scripts with sample rows before production"],"tags":["kettle","javascript","arity","script-function"],"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"}