pentaho/pentaho-kettle · error
The function call truncDate requires 2 arguments: a date…
Error message
The function call truncDate requires 2 arguments: a date and a level (int)
What it means
truncDate(date, level) truncates a java.util.Date to a granularity level (0=ms ... 5=month). This error is thrown when the JS call does not pass exactly 2 arguments, i.e. the date and an integer level. It signals an invalid signature, separate from the level range error thrown later inside truncDate.
Solutions
- Pass exactly two arguments: a Date and an integer level, e.g. truncDate(orderDate, 5) (5=month start).
- Convert string dates first: truncDate(str2date(s, 'yyyy-MM-dd'), 4).
- Ensure the level is a whole number (levels 0-5); use parseInt(level, 10).
- Review the source switch: 0=millisecond,1=second,2=minute,3=hour,4=day,5=month.
Example fix
// before
var d = truncDate('2024-01-15', 'MM');
// after
var d = truncDate(str2date('2024-01-15', 'yyyy-MM-dd'), 5); Defensive patterns
Strategy: validation
Validate before calling
function safeTruncDate(d, lvl) { if (!(d instanceof Date) || lvl == null || lvl < 0 || lvl > 5 || lvl !== Math.floor(lvl)) return null; return truncDate(d, lvl); } Type guard
function isTruncLevel(v) { return typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 5; } Try / catch
try { d = truncDate(dt, lvl); } catch (e) { Logger.LogError('truncDate failed: ' + e.message); d = null; } Prevention
- Always pass exactly 2 arguments: a Date and an int level 0-5
- Convert string dates with str2date before calling
- Remember level scale: 0=ms,1=sec,2=min,3=hour,4=day,5=month
When it happens
Trigger: truncDate() with zero/one argument, truncDate(d) missing the level, truncDate(d, 'MONTH') passing a string level instead of an int, or more than 2 arguments in the JS step.
Common situations: Passing a string date like '2024-01-15' plus a string format; using Oracle-style TRUNC(date,'MM') semantics; level supplied as a float like 2.0 from JS math.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- The function call truncDate requires 2 arguments: a date…
- Argument of TRUNC of date has to be between 0 and 5
- Argument of TRUNC of date has to be between 0 and 5
- Please provide a valid date to the function call date2str.
- Please provide a valid string to the function call str2date.
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/d2d67dce8bec6287.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:2521
return null;
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
// This is the truncation of a date...
// The second argument specifies the level: ms, s, min, hour, day, month, year
//
Date dArg1 = null;
Integer level = null;
try {
dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
level = (Integer) Context.jsToJava( ArgList[1], Integer.class );
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
return truncDate( dArg1, level );
} else {
throw Context
.reportRuntimeError( "The function call truncDate requires 2 arguments: a date and a level (int)" );
}
}
@VisibleForTesting
static Date truncDate( Date dArg1, Integer level ) {
Calendar cal = Calendar.getInstance();
cal.setTime( dArg1 );
switch ( level.intValue() ) {
// MONTHS
case 5:
cal.set( Calendar.MONTH, 0 );
// DAYS
case 4:
cal.set( Calendar.DAY_OF_MONTH, 1 );
// HOURS
case 3:View on GitHub (pinned to f3058517a1)