Creating a Bank Statement Parser Plug-in Script File

You must implement each Bank Statement Parser Plug-in interface function in a Javascript file (with a .js extension). You can use the SuiteCloud IDE, another Javascript IDE, or a text editor to create the plug-in implementation script file.

This plug-in uses SuiteScript 2.0. Begin your implementation script file with this comment:

The following is a parser sample:

          /**
 * @NApiVersion 2.0
 * @NScriptType bankStatementParserPlugin 
 */ 

        
          /**
 * @NApiVersion 2.0
 * @NScriptType bankStatementParserPlugin
 */
define(['N/file', 'N/log'],
   function(file, log)   {
      return {
         parseBankStatement: function (context) {

            var accountStatement = context.output.createNewAccountStatement();
            accountStatement.accountMappingKey = defaultAccountMappingKey;
            log.debug({
               title: 'Adding a new account statement',
               details: accountStatement
            });

            var accountStatementId = context.output.addAccountStatement({"parsedAccountStatement":accountStatement});
            log.debug({
               title: 'New account statement ID',
               details: accountStatementId
            });

            var statementFile = context.input.file;

            var statementLineIterator = statementFile.lines.iterator();
            statementLineIterator.next();
            statementLineIterator.each(function (line) {
               log.debug({
                  title: 'Read a line from the statement',
                  details: line.value
               });

         var formatProfileId = context.input.formatProfileId;
        log.debug({
            title: 'Format Profile Id',
            details: formatProfileId

            });
               var partsOfCSVLine = line.value.split(',');
               var transaction = context.output.createNewTransaction();
               transaction.accountStatementId = accountStatementId;
               var rawDate = partsOfCSVLine[0];
               transaction.date = rawDate.substring(6, 10) + '-' + rawDate.substring(0, 2) + '-' + rawDate.substring(3, 5);
               transaction.amount = partsOfCSVLine[4];
               transaction.transactionMappingKey = partsOfCSVLine[3];
               transaction.transactionNumber = partsOfCSVLine[2];
               transaction.payee = partsOfCSVLine[1];
               transaction.currency = "USD";
               transaction.memo = partsOfCSVLine[5];
               transaction.customerRawId = partsOfCSVLine[6];
               transaction.customerName = partsOfCSVLine[7];
               transaction.invoices = partsOfCSVLine[8].split(',');

               log.debug({
                  title: 'Adding a new transaction',
                  details: transaction
               });

               context.output.addTransaction({"parsedTransaction":transaction});
               return true;
            });

         },
         getStandardTransactionCodes: function (context) {
            var tranTypes = ["ACH", "CHECK", "CREDIT", "DEBIT", "DEPOSIT", "FEE", "INTEREST", "PAYMENT", "TRANSFER", "OTHER"];
            for (var i = 0; i < tranTypes.length; ++i)
            {
               var standardTransactionCode = context.output.createNewStandardTransactionCode();
               standardTransactionCode.tranCode = tranTypes[i];
               standardTransactionCode.tranType = tranTypes[i];
               context.output.addStandardTransactionCode({"standardTransactionCode":standardTransactionCode});

               log.debug({
                  title: 'Adding a new standard transaction code',
                  details: standardTransactionCode
               });
            }
         }
      }
   }
); 

        

To surface user-facing error messages that are readable, you must raise error messages as simple strings in the plug-in script. Currently, throwing error objects generates errors as JSON strings to users, which are not easily readable. For examples of raising an error message as a simple string, see the sample strings below:

          throw('The file could not be imported because the currency code is not valid.'); 

        
          var translateableErrorMessage = translation.get({collection: 'my_errors', key: 'CURRENCY_ERROR'})(); throw(translateableErrorMessage); 

        

In the second example, translation.get is a SuiteScript API that can be implemented by plug-in authors if they wish to translate strings. For more information about translation, see N/translation Module.

Your plug-in script should contain all logic required for your implementation. The following table describes the functions that you must implement in the plug-in script file. For details about the required functions and their objects, see Bank Statement Parser Plug-in Interface Definition.

The following table describes the interface functions:

Function

Description

parseBankStatement

(BankStatementParserContext)

Parse a streamed bank statement.

This function can stream bank statement file content and obtain default settings for the file. This function adds the parsed transactions and account statements to NetSuite.

BankStatementParserContext is the context for this function.

getStandardTransactionCodes

(StandardTransactionCodeContext)

Store the standard transaction code mapping in NetSuite.

This function contains information that maps the transaction code from the parsed transactions to the corresponding NetSuite transaction types.

StandardTransactionCodeContext is the context for this function.

Rules and Guidelines for Creating a Plug-in Implementation Script File

Use the following rules and guidelines when creating the plug-in implementation script file:

Related Topics

General Notices