Sidebar

Can I add blank fields in a csv or pipe delimited file?

0 votes
380 views
asked Nov 30, 2016 by brandon-w-8204 (31,800 points)

I have this:

Test|test,test|test@test.com|test|1234|12/25/2013|12/25/2013|12345|M

I need this:

Test|test,test|||test@test.com|test|1234|12/25/2013|12/25/2013|12345|M

1 Answer

0 votes

Use the following code

//use this for comma separated files
var originalMessage = qie.parseCSVString(message.getNode('/'));
// message.setNode('/', '');
for (var i = 1; i <= originalMessage.getRowCount(); i++) {
   var row = qie.parseCSVString(originalMessage.getNode('*', i));
   var fieldCount = 1;
   while (row.checkNodeExists(fieldCount)) {
      fieldCount++;
   }
   fieldCount--;
   qie.debug('fieldCount: ' + fieldCount);
   //loop through each field and skip field 3 and 4
   for (var j = 1; j <= fieldCount; j++) {
      if (j <= 2) {
         message.setNode(j, originalMessage.getNode(j, i), i);
      } else {
         message.setNode(j+2, originalMessage.getNode(j, i), i);
      }
      message.setNode('3', '', i);
      message.setNode('4', '', i);
   }
}

//Use this for pipe delimited files
// var originalMessage = qie.parseCSVString(message.getNode('/'), false, '"', '|', false);
// // message.setNode('/', '');
// for (var i = 1; i <= originalMessage.getRowCount(); i++) {
//    var row = qie.parseCSVString(originalMessage.getNode('*', i), false, '"', '|', false);
//    var fieldCount = 1;
//    while (row.checkNodeExists(fieldCount)) {
//       fieldCount++;
//    }
//    fieldCount--;
//    qie.debug('fieldCount: ' + fieldCount);
//    //loop through each field and skip field 3 and 4
//    for (var j = 1; j <= fieldCount; j++) {
//       if (j <= 2) {
//          message.setNode(j, originalMessage.getNode(j, i), i);
//       } else {
//          message.setNode(j+2, originalMessage.getNode(j, i), i);
//       }
//       message.setNode('3', '', i);
//       message.setNode('4', '', i);
//    }
// }

answered Nov 30, 2016 by brandon-w-8204 (31,800 points)
...