qie.createCSVMessage¶
Signature: qie.createCSVMessage(template*, quoteValues*, quoteChar*, separator*, encoding*, headerRow*)
Returns: CSV Message message - the newly created message object
Replace the current message with an empty CSV formatted message.
Note
The return value MUST ALWAYS be assigned to the bound-in message object.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String | template* | (optional) the CSV template | null |
| Boolean | quoteValues* | (optional) specifies whether or not to surround individual values with quotes | true |
| String | quoteChar* | (optional) the quote character to use when surrounding values | " |
| String | separator* | (optional) the separator character to use | , |
| String | encoding* | (optional) the character encoding for this message | Source Node encoding |
| Boolean | headerRow* | (optional) specifies whether or not a header row will be present on the message | false |
Example¶
// Example: create and populate a CSV message.
message = qie.createCSVMessage(
'Name,Age,Email', // template: header row / column structure
true, // quoteValues: surround values with quotes
'"', // quoteChar: character used for quoting
',', // separator: column delimiter
'UTF-8', // encoding: character encoding
true // headerRow: CSV includes a header row
);
// Populate rows
message.setNode('1[1]', 'David Jones');
message.setNode('2[1]', 58);
message.setNode('3[1]', 'djones@gmail.com');
message.setNode('1[2]', 'Jaime B. Smith');
message.setNode('2[2]', 22);
message.setNode('3[2]', 'smi@gmail.com');
// Append a new row dynamically
var lastRow = Number(message.getRowCount());
message.setNode('1[' + (lastRow + 1) + ']', 'Robert Frost');
message.setNode('2[' + (lastRow + 1) + ']', 32);
message.setNode('3[' + (lastRow + 1) + ']', 'frosty@yahoo.com');
qie.debug("Number of rows: " + message.getRowCount());