pentaho/pentaho-kettle · error · JavaScriptException
The function call year requires 1 argument.
Error message
The function call year requires 1 argument.
What it means
The year() JavaScript function extracts the calendar year from a Date argument and returns it as a number. When it is not called with exactly one argument, it throws this runtime error before any date conversion happens.
Solutions
- Call year() with exactly one argument.
- Pass a java.util.Date (use str2Date() first if you have a string).
- Null-check the date field before calling.
- Convert string dates explicitly: year(str2Date(dateStr, 'yyyy-MM-dd')).
Example fix
// before var y = year(); // after var y = year(myDateField); // myDateField is a Date from str2Date()
Defensive patterns
Strategy: validation
Validate before calling
if (myDateField == null) throw 'year: date is null'; var y = year(myDateField);
Type guard
function isDate(v) { return v != null && v.getClass && String(v.getClass()) === 'class java.util.Date'; } Try / catch
try { var y = year(myDateField); } catch (e) { var y = null; } Prevention
- Pass exactly one argument to year()
- Convert string dates with str2Date() first
- Null-check date fields from upstream steps
- Confirm field type is Date in the step's field grid
When it happens
Trigger: Calling year() in a modified JavaScript step with zero arguments, or with two or more arguments; also when the argument is null the arity check (length==1) may pass but the cast then fails with a different wrapped message.
Common situations: Scripts ported from SQL YEAR() semantics with different argument expectations, forgetting to pass the date field, or passing a date string instead of a Date object.
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 month requires 1 argument.
- The function call quarter requires 1 argument.
- The function call week requires 1 argument.
- Error in isEmpty function:
- Script.Log.CouldNotAddDefaultConstants
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/23de1928d6fbf50a.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:871
}
return null;
}
public static Object year( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
Calendar cal = Calendar.getInstance();
cal.setTime( dArg1 );
return new Double( cal.get( Calendar.YEAR ) );
} else {
throw Context.reportRuntimeError( "The function call year requires 1 argument." );
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
}
public static Object month( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
try {
if ( ArgList.length == 1 ) {
if ( isNull( ArgList[0] ) ) {
return new Double( Double.NaN );
} else if ( isUndefined( ArgList[0] ) ) {
return Context.getUndefinedValue();
}
java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
Calendar cal = Calendar.getInstance();
cal.setTime( dArg1 );View on GitHub (pinned to f3058517a1)