{"record":{"id":"25d4c68418e6aabb","repo":"pentaho/pentaho-kettle","slug":"the-function-call-dateadd-requires-3-arguments","errorCode":null,"errorMessage":"The function call dateAdd requires 3 arguments.","messagePattern":"The function call dateAdd requires 3 arguments\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":681,"sourceCode":"            int day = cal.get( Calendar.DAY_OF_WEEK );\n            cal.add( Calendar.DATE, 1 );\n            if ( ( day != Calendar.SATURDAY ) && ( day != Calendar.SUNDAY ) ) {\n              iOffset++;\n            }\n          }\n        } else if ( strType.equals( \"hh\" ) ) {\n          cal.add( Calendar.HOUR, iValue );\n        } else if ( strType.equals( \"mi\" ) ) {\n          cal.add( Calendar.MINUTE, iValue );\n        } else if ( strType.equals( \"ss\" ) ) {\n          cal.add( Calendar.SECOND, iValue );\n        }\n        return cal.getTime();\n      } catch ( Exception e ) {\n        throw new RuntimeException( e.toString() );\n      }\n    } else {\n      throw new RuntimeException( \"The function call dateAdd requires 3 arguments.\" );\n    }\n  }\n\n  public static String fillString( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,\n    Object FunctionContext ) {\n    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {\n          return null;\n        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {\n          return (String) undefinedValue;\n        }\n        String fillChar = (String) ArgList[0];\n        int count = (Integer) ArgList[1];\n        if ( fillChar.length() != 1 ) {\n          throw new RuntimeException( \"Please provide a valid Char to the fillString\" );\n        } else {\n          char[] chars = new char[count];","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L663-L699","documentation":"dateAdd requires exactly three arguments: the date, the integer amount to add, and the unit string. When ArgList.length != 3 the function short-circuits and throws this RuntimeException before doing any work. It is an argument-count guard, thrown from the else branch of the argument check.","triggerScenarios":"Calling dateAdd() with fewer than three arguments or more than three, e.g. dateAdd(date, 'dd') (missing amount) or dateAdd(date, 1, 'dd', extra).","commonSituations":"Confusing this API with java.util-style APIs that take (unit, amount, date); forgetting the unit argument; passing an options object instead of positional arguments.","solutions":["Call with exactly three positional arguments: dateAdd(date, amount, unit).","Add the missing amount or unit argument.","Split extra data into separate script variables instead of additional arguments."],"exampleFix":"// before\nvar newDate = dateAdd(orderDate, 'dd');\n// after\nvar newDate = dateAdd(orderDate, 7, 'dd');","handlingStrategy":"validation","validationCode":"if (arguments.length !== 3) {\n  throw new Error('dateAdd requires exactly 3 arguments: (date, amount, unit)');\n}\nvar newDate = dateAdd(dateField, amount, unit);","typeGuard":"function hasThreeArgs() { return arguments.length === 3; }","tryCatchPattern":"try {\n  var newDate = dateAdd(dateField, amount, unit);\n} catch (e) {\n  if (String(e.message).indexOf('requires 3 arguments') !== -1) {\n    throw new Error('Call dateAdd as dateAdd(date, amount, unit)');\n  } else { throw e; }\n}","preventionTips":["Remember the signature: dateAdd(date, amount, unit) — three positional arguments.","Do not pass options objects or extra parameters.","Centralize date arithmetic in one reviewed script function per transformation."],"tags":["javascript","argument-count","pentaho-kettle"],"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"}