{"record":{"id":"cca0518d1a829124","repo":"pentaho/pentaho-kettle","slug":"the-function-call-dateadd-requires-3-arguments-cca051","errorCode":null,"errorMessage":"The function call dateAdd requires 3 arguments.","messagePattern":"The function call dateAdd requires 3 arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":711,"sourceCode":"            cal.add( Calendar.DATE, 1 );\n            int day = cal.get( Calendar.DAY_OF_WEEK );\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 Context.reportRuntimeError( e.toString() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call dateAdd requires 3 arguments.\" );\n    }\n  }\n\n  public static String fillString( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function 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) Context.getUndefinedValue();\n        }\n        String fillChar = Context.toString( ArgList[0] );\n        int count = (int) Context.toNumber( ArgList[1] );\n        if ( fillChar.length() != 1 ) {\n          throw Context.reportRuntimeError( \"Please provide a valid Char to the fillString\" );\n        } else {\n          char[] chars = new char[count];","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L693-L729","documentation":"dateAdd is a Kettle Rhino extension function that adds an amount of a given unit (y, M, d, h, m, s) to a date. It requires exactly 3 arguments: date, unit string, and integer amount. Any other argument count throws this RuntimeError.","triggerScenarios":"Calling dateAdd with 2 arguments (missing the amount) or 4+ arguments; passing the unit and amount in the wrong order still passes the count check but the runtime error appears when the count differs.","commonSituations":"Scripts ported from other JS date libraries with different signatures (e.g. moment-style dateAdd(d, {days:1})); the increment value stored in a field that is null/undefined so the developer removed it.","solutions":["Call with three arguments: dateAdd(myDate, 'd', 1)","Make sure the amount is a number, not a string, to avoid the exception path inside the try block","Check that all three values are defined before the call"],"exampleFix":"// before\nvar later = dateAdd(now, 'd');\n// after\nvar later = dateAdd(now, 'd', 1);","handlingStrategy":"validation","validationCode":"if (arguments.length !== 3) throw new Error('dateAdd(date, unit, amount) requires 3 arguments');\nif (typeof amount !== 'number') amount = parseInt(amount, 10);","typeGuard":null,"tryCatchPattern":"try { var nd = dateAdd(d, unit, n); } catch (e) { throw new Error('dateAdd misuse: ' + e.message); }","preventionTips":["Use the fixed order: date, unit string, numeric amount","Coerce field-based amounts to numbers before calling","Do not pass moment/date-fns style objects"],"tags":["javascript","kettle","date","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"}