How do I remove the empty last row from a CSV message?

+1 vote
asked Feb 22, 2022 by ron-s-6919 (4,480 points)
When I create a CSV message, there is an empty row at the bottom.  It may be created because there is a line ending after the last row of data.  How can I remove this empty bottom row from the CSV message?

1 Answer

+2 votes
Best answer

To remove the last empty row do the following code:

//Remove last empty row
var csv = message.getNode('/');
csv = StringUtils.substringBeforeLast(csv, '\n');
qie.debug('csv: ' + csv);
message = qie.createTextMessage(csv);

Note: This will be the last mapping. If you convert the message back to a CSV then it will put the empty row back. This means that you can no longer use the message.setNode with a CSV path.

answered Feb 23, 2022 by brandon-w-8204 (33,330 points)
selected Mar 1, 2022 by nathan-c-4426