{"record":{"id":"f47ed028948cffb7","repo":"pentaho/pentaho-kettle","slug":"the-function-call-month-requires-1-argument-f47ed0","errorCode":null,"errorMessage":"The function call month requires 1 argument.","messagePattern":"The function call month 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":892,"sourceCode":"      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 );\n        return new Double( cal.get( Calendar.MONTH ) );\n      } else {\n        throw Context.reportRuntimeError( \"The function call month requires 1 argument.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n\n  }\n\n  public static Object quarter( 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();","sourceCodeStart":874,"sourceCodeEnd":910,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L874-L910","documentation":"The month() JavaScript function returns the calendar month of a Date argument as a number (0-based, per java.util.Calendar.MONTH). It throws this runtime error when not called with exactly one argument.","triggerScenarios":"Calling month() with zero or multiple arguments in a modified JavaScript step; or with an argument that fails the Date conversion, which is then re-thrown as e.toString().","commonSituations":"Forgetting the date field argument, passing a date string without str2Date(), or expecting 1-based month semantics and misreading the result afterwards.","solutions":["Call month() with exactly one Date argument.","Convert string dates with str2Date() before calling month().","Null-check the field; note the result is 0-based (add 1 for human-readable month).","Verify the field type is Date in the step's field definitions."],"exampleFix":"// before\nvar m = month();\n// after\nvar m = month(myDateField) + 1; // Calendar.MONTH is 0-based","handlingStrategy":"validation","validationCode":"if (myDateField == null) throw 'month: date is null';\nvar m = month(myDateField) + 1; // 0-based","typeGuard":"function isDate(v) { return v != null && v.getClass && String(v.getClass()) === 'class java.util.Date'; }","tryCatchPattern":"try { var m = month(myDateField) + 1; } catch (e) { var m = null; }","preventionTips":["Pass exactly one Date argument","Remember Calendar.MONTH is 0-based (Jan=0)","Use str2Date() for string inputs","Validate the field type before date functions"],"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"}