Parsing a text file with no headers in a flow designer action.

Jacob Nan
Tera Guru

What I'm trying to do may not be possible or realistic, but I would like the parse the data of a csv file that I receive from a vendor. The difficulty about reading this file is that there are no headers and an inconsistent number of columns. Each line has a 2-digit identifier in the first column that represents the type of data in the line. I was able to convert the in a business rule by converting bytes to string and then splitting twice by '/n' and the delimiter '|'. 

 

What I would like to be able to do is do the same thing in a flow designer action but parse each line as an object and create an array of only values with the desired 2-digit identifier. I've tried using the CSVparser and just moving the business rule into the flow action.

 

The two main errors I've received are "Table name cannot be null" and "cannot convert org.mozilla.javascript.nativearray@880c92 to java.lang.character"

 

(function execute(inputs, outputs) {
var attachment = new GlideRecord('sys_attachment');
      attachment.addQuery('sys_id', inputs.sysid);
      attachment.query();
if(attachment.next()){


var bytesContent = new GlideSysAttachment().getBytes(attachment);
var base64ImageStr = GlideStringUtil.base64Encode(bytesContent);
var strData = Packages.java.lang.String(bytesContent)

//var delimiter = '|'
//var headers = ['record_type','bill_payer','display_btn','billing_cycle','bill_date','adjustments','monthly_recurring_charges','non_recurring_prorate','usage_charges','taxes','surcharges','invoice_number']
var cArray = strData.split('/n');
gs.info(cArray);
var objectArray = [];

for(var i = 0;i<cArray.length();i++){
      var lArray = cArray.split('|');
      gs.info(lArray);
      if(lArray[0] == '05'){
//            var cArray = new sn_impex.CSVParser().parseLineToArray(strData,headers,delimiter);
            var record = {};
            record.recordType = lArray[0]
            record.billPayer = lArray[1]
            record.displayBTN = lArray[2]
            record.billingCycle = lArray[3]
            record.billDate = lArray[4]
            record.adjustments = lArray[5]
            record.monthlyRecurringCharges = lArray[6]
            record.nonRecurringProrate = lArray[7]
            record.usageCharges = lArray[8]
            record.taxes = lArray[0]
            record.surcharges = lArray[0]
            record.invoiceNumber = lArray[0]
            objectArray.push(record);
      }

}}
outputs.variable = objectArray
})(inputs, outputs);

 

Any help is greatly apreciated!

0 REPLIES 0