pentaho/pentaho-kettle · error · RuntimeException

The function call getDayNumber requires 2 arguments.

Error message

The function call getDayNumber requires 2 arguments.

What it means

getDayNumber(datePart, date) is a Script step JavaScript helper that returns the numeric day value of a date. It requires exactly two arguments and throws this RuntimeException when the argument count differs, since it cannot guess which date or which date part the caller intended.

Solutions

  1. Call with exactly two arguments: getDayNumber('d', myDate) — date part selector first, then the date.
  2. Verify the date argument is a valid Date object, not a string.
  3. Consult the Script step function reference for the exact signature.

Example fix

// before
var d = getDayNumber(myDate);
// after
var d = getDayNumber('d', myDate);
Defensive patterns

Strategy: validation

Validate before calling

if (myDate instanceof Date) { var d = getDayNumber('d', myDate); }

Type guard

function isDate(v) { return v instanceof Date && !isNaN(v.getTime()); }

Try / catch

try { var d = getDayNumber('d', myDate); } catch (e) { if (/getDayNumber requires 2 arguments/.test(String(e))) { d = null; } else { throw e; } }

Prevention

When it happens

Trigger: Calling getDayNumber() in script with fewer or more than two arguments, e.g. getDayNumber(date) or getDayNumber('d', date, extra).

Common situations: Migrating scripts between Kettle/Pentaho versions where the signature changed; forgetting the date-part selector argument; extra args added by copy-paste.

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


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/e2061915f06ef0df. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:447

          Calendar startDate = Calendar.getInstance();
          startDate.setTime( dIn );
          if ( strType.equals( "y" ) ) {
            return new Double( startDate.get( Calendar.DAY_OF_YEAR ) );
          } else if ( strType.equals( "m" ) ) {
            return new Double( startDate.get( Calendar.DAY_OF_MONTH ) );
          } else if ( strType.equals( "w" ) ) {
            return new Double( startDate.get( Calendar.DAY_OF_WEEK ) );
          } else if ( strType.equals( "wm" ) ) {
            return new Double( startDate.get( Calendar.DAY_OF_WEEK_IN_MONTH ) );
          }
          return new Double( startDate.get( Calendar.DAY_OF_YEAR ) );
        }
      } catch ( Exception e ) {
        return null;
        // throw new RuntimeException(e.toString());
      }
    } else {
      throw new RuntimeException( "The function call getDayNumber requires 2 arguments." );
    }
  }

  public static Object isWorkingDay( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    if ( ArgList.length == 1 ) {
      try {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return undefinedValue;
        } else {
          java.util.Date dIn = (java.util.Date) ArgList[0];
          Calendar startDate = Calendar.getInstance();
          startDate.setTime( dIn );
          if ( startDate.get( Calendar.DAY_OF_WEEK ) != Calendar.SATURDAY
            && startDate.get( Calendar.DAY_OF_WEEK ) != Calendar.SUNDAY ) {
            return Boolean.TRUE;

View on GitHub (pinned to f3058517a1)