downloadPreviousDayBankStatementFile (context)

Example

The following is an example of the whole downloadPreviousDayBankStatementFile function:

             downloadPreviousDayBankStatementFile: function (context) {
    var config = context.input.pluginConfiguration;
   var connection = sftp.createConnection({
      url: config.getConfigurationFieldValue({fieldName:"url"}),
      passwordGuid: config.getConfigurationFieldValue({fieldName:"password"}),
      hostKey: config.getConfigurationFieldValue({fieldName:"hostKey"}),
      hostKeyType: config.getConfigurationFieldValue({fieldName:"hostKeyType"}),
      username: config.getConfigurationFieldValue({fieldName:"username"}),
      port: parseInt(config.getConfigurationFieldValue({fieldName:"port"}))
   );
   var downloadedFile = connection.download({
      filename: config.getConfigurationFieldValue({fieldName:"filename"}),
      directory: config.getConfigurationFieldValue({fieldName:"directory"}),
      timeout: parseInt(config.getConfigurationFieldValue({fieldName:"timeout"}))
   });
   context.output.saveBankStatementFile({file: downloadedFile, bankStatementFormat: config.getConfigurationFieldValue({fieldName:"format"})}); 

        

As in this example, first create a convenience variable to easily reference the plug-in configuration values, which are provided as input to the function:

              var config = context.input.pluginConfiguration; 

        

Create the sFTP connection by using the SuiteScript 'N/sftp' module.

Provide the configuration values for the fields from the defined getRequiredConfigurationFields (context). The fieldName property in config.getConfigurationFieldValue maps directly to the dataName property in the getRequiredConfigurationFields definition. To define each configuration field line in getRequiredConfigurationFields, see addConfigurationField.

             var connection = sftp.createConnection({
         url: config.getConfigurationFieldValue({fieldName:"url"}),
       passwordGuid: config.getConfigurationFieldValue({fieldName:"password"}),
      hostKey: config.getConfigurationFieldValue({fieldName:"hostKey"}),
        hostKeyType: config.getConfigurationFieldValue({fieldName:"hostKeyType"}),
      username: config.getConfigurationFieldValue({fieldName:"username"}),
      port: parseInt(config.getConfigurationFieldValue({fieldName:"port"}))
    }); 

        

Using the set configuration field values for the file name and directory, download the file to the NetSuite server.

Based on your bank’s conventions, you may need to create functions to determine the file name or directory. For example, your bank may require the file name to include the date.

In our sample, there is a single directory containing a file that regenerates with new content once a day.

             var downloadedFile = connection.download({
       filename: config.getConfigurationFieldValue({fieldName:"filename"}),
       directory: config.getConfigurationFieldValue({fieldName:"directory"}),
       timeout: parseInt(config.getConfigurationFieldValue({fieldName:"timeout"}))
    }); 

        

Lastly, provide the downloaded file back to the NetSuite system. Once in NetSuite, the administrator can import the file and automatic matching runs on the statement transactions.

              context.output.saveBankStatementFile({file: downloadedFile, bankStatementFormat: config.getConfigurationFieldValue({fieldName:"format"})}); 

        

Related Topics

Bank Connectivity Plug-in Interface Definition
getRequiredConfigurationFields (context)
Object Types

General Notices