{"record":{"id":"23de1928d6fbf50a","repo":"pentaho/pentaho-kettle","slug":"the-function-call-year-requires-1-argument-23de19","errorCode":null,"errorMessage":"The function call year requires 1 argument.","messagePattern":"The function call year requires 1 argument\\.","errorType":"exception","errorClass":"JavaScriptException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":871,"sourceCode":"    }\n    return null;\n  }\n\n  public static Object year( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return Context.getUndefinedValue();\n        }\n        java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );\n        return new Double( cal.get( Calendar.YEAR ) );\n      } else {\n        throw Context.reportRuntimeError( \"The function call year requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static Object month( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 1 ) {\n        if ( isNull( ArgList[0] ) ) {\n          return new Double( Double.NaN );\n        } else if ( isUndefined( ArgList[0] ) ) {\n          return Context.getUndefinedValue();\n        }\n        java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n        Calendar cal = Calendar.getInstance();\n        cal.setTime( dArg1 );","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L853-L889","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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'))."],"exampleFix":"// before\nvar y = year();\n// after\nvar y = year(myDateField); // myDateField is a Date from str2Date()","handlingStrategy":"validation","validationCode":"if (myDateField == null) throw 'year: date is null';\nvar y = year(myDateField);","typeGuard":"function isDate(v) { return v != null && v.getClass && String(v.getClass()) === 'class java.util.Date'; }","tryCatchPattern":"try { var y = year(myDateField); } catch (e) { var y = null; }","preventionTips":["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"],"tags":["javascript","rhino","date-functions"],"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"}