pentaho/pentaho-kettle · error · JavaScriptException
The function call week requires 1 argument.
Error message
The function call week requires 1 argument.
What it means
Argument-count guard in ScriptValuesAddedFunctions.week, which returns the ISO week number of a given Date as a Double. It fires when the script calls week with an argument count other than exactly 1; a Rhino runtime error is raised instead of computing the week. Fix by passing exactly one Date argument, e.g. week(orderDate).
Solutions
- Call week() with exactly one Date argument.
- Convert string dates with str2Date() before calling.
- Null-check the field value.
- Be aware week numbering depends on the JVM's locale/calendar; normalize if needed.
Example fix
// before var w = week(); // after var w = week(myDateField);
Defensive patterns
Strategy: validation
Validate before calling
if (myDateField == null) throw 'week: date is null'; var w = week(myDateField);
Type guard
function isDate(v) { return v != null && v.getClass && String(v.getClass()) === 'class java.util.Date'; } Try / catch
try { var w = week(myDateField); } catch (e) { var w = null; } Prevention
- Pass exactly one Date argument
- Use str2Date() for string inputs
- Account for locale-dependent week numbering
- Null-check upstream date fields
When it happens
Trigger: Calling week() with zero or multiple arguments in a modified JavaScript step, or with a value that cannot be cast to java.util.Date.
Common situations: Forgotten date argument, string dates not converted with str2Date(), locale-dependent week numbering surprises after the call succeeds.
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 year 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/dc4082c9a71ab309.
Report an issue: GitHub.
Appendix: source
Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:946
throw Context.reportRuntimeError( e.toString() );
}
}
public static Object week( 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.WEEK_OF_YEAR ) );
} else {
throw Context.reportRuntimeError( "The function call week requires 1 argument." );
}
} catch ( Exception e ) {
throw Context.reportRuntimeError( e.toString() );
}
}
public static Object str2RegExp( Context actualContext, Scriptable actualObject, Object[] ArgList,
Function FunctionContext ) {
String[] strArr = null;
if ( ArgList.length == 2 ) {
try {
if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
return null;
} else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
return Context.getUndefinedValue();
}
String strToMatch = Context.toString( ArgList[0] );
Pattern p = Pattern.compile( Context.toString( ArgList[1] ) );View on GitHub (pinned to f3058517a1)