{"record":{"id":"9e76a35cb08ec9c1","repo":"pentaho/pentaho-kettle","slug":"the-function-call-appendtofile-requires-arguments-9e76a3","errorCode":null,"errorMessage":"The function call appendToFile requires arguments.","messagePattern":"The function call appendToFile requires arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":224,"sourceCode":"      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static void appendToFile( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {\n      try {\n        FileOutputStream file = new FileOutputStream( Context.toString( ArgList[0] ), true );\n        DataOutputStream out = new DataOutputStream( file );\n        out.writeBytes( Context.toString( ArgList[1] ) );\n        out.flush();\n        out.close();\n      } catch ( Exception er ) {\n        throw Context.reportRuntimeError( er.toString() );\n      }\n    } else {\n      throw Context.reportRuntimeError( \"The function call appendToFile requires arguments.\" );\n    }\n  }\n\n  public static Object getFiscalDate( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n\n    if ( ArgList.length == 2 ) {\n      try {\n        if ( isNull( ArgList ) ) {\n          return null;\n        } else if ( isUndefined( ArgList ) ) {\n          return Context.getUndefinedValue();\n        }\n        java.util.Date dIn = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );\n        Calendar startDate = Calendar.getInstance();\n        Calendar fisStartDate = Calendar.getInstance();\n        Calendar fisOffsetDate = Calendar.getInstance();\n        startDate.setTime( dIn );","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L206-L242","documentation":"appendToFile is a custom JavaScript function registered by ScriptValuesAddedFunctions for the ScriptValuesMod (Modified Java Script Value) step in Pentaho Kettle. It requires at least one argument (the text to append and optionally the target filename); when called with zero arguments it throws a Rhino RuntimeException instead of silently doing nothing.","triggerScenarios":"Calling appendToFile() with ArgList.length == 0 from the JavaScript pane of a Modified Java Script Value step.","commonSituations":"Typing the function name to test it without arguments; a field/variable expression that evaluates to nothing so no arguments are bound; copy-pasted sample code where the call arguments were accidentally deleted.","solutions":["Pass the required arguments: appendToFile(filename, textToAppend) in the script.","Check that the preceding argument expression (field, variable) is not empty or deleted.","Wrap the call in a JS guard: if (typeof myText !== 'undefined') appendToFile('log.txt', myText);"],"exampleFix":"// before\nappendToFile();\n// after\nappendToFile('output.txt', myTextField + '\\n');","handlingStrategy":"validation","validationCode":"// in the JS step, before calling\nif (typeof myText === 'undefined' || arguments.length < 1) {\n  throw 'appendToFile needs (filename, text)';\n}\nappendToFile('out.txt', myText);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call ScriptValues added functions with zero arguments while testing.","Keep argument expressions bound to non-deleted fields.","Wrap optional appends in a typeof undefined check."],"tags":["javascript","argument-count","pdi-kettle"],"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"}