Sidebar

How can I create a CSV message with headers?

0 votes
623 views
asked Aug 29, 2017 by brandon-w-8204 (33,270 points)
I need a CSV message with headers, how can I accomplish this?

1 Answer

0 votes

There a 2 ways to have a CSV message with headers.

1. If your source is a CSV with headers you can check the Header Row on the source message and it will have headers.

2. Create a new CSV message that has headers using a custom script:

// Set the message to a csv with headers
// parameters for qie.createCSVMessage(quoteValues*, 'quoteChar*', 'separator*', 'encoding*', headerRow*);
message = qie.createCSVMessage(true, '"', ',', 'UTF-8', true);

//set the message to the values - Note the first row in the CSV you set will be the header row
var newCsvString = '"header 1","header 2"';
message.setNode('/', newCsvString);

//set a row in the new csv message
message.setNode('header 1', 'row 1 value 1');
message.setNode('header 2', 'row 1 value 2');

//set a new row in the new csv message
var rowCount = message.getRowCount();
message.setNode('header 1[' + (rowCount*1 + 1) + ']', 'row 2 value 1');
message.setNode('header 2[' + (rowCount*1 + 1) + ']', 'row 2 value 2');

answered Aug 29, 2017 by brandon-w-8204 (33,270 points)
...