Skip to content

CSV Node Path Syntax

A CSV message stores tabular data (numbers and text) in plain-text form organized by rows and columns. A CSV node path references a specific row and column (cell) in a CSV message. The CSV node path syntax conforms to the following pattern.

Node paths in this section can be used with getNode, getAllNodes, and other QIE functions that accept a nodePath parameter. See How Node Paths Resolve for behavior details and the Node Path Lookup Dialog to build and validate them interactively against a sample message.

Column ID [ Row Index ]
Element Required Description
Column ID Required *

1) The column index (the first column is index '1', the second column is index '2', etc.), or 2) The column name, matched case-insensitively against the header row (header values are trimmed before comparison; the supplied name is not). Slashes, spaces, and other punctuation in a header are fine as long as the path uses the same characters.

3) '*' or '/' to indicate all columns

Row Index Optional The row index (where the first row is index '1', the second row is index '2', etc.)
If the row index is omitted, the first row (row index = 1) is used
Row index '0' is the header row. See Reading the Header Row

*Row Index is not required when specifying the root node identifier (/) as the node path

CSV Node Path Examples:

CSV Node Path Description
/ Returns the entire CSV message
LastName Returns column 'LastName' of row 1

LastName[1]

or

LastName, 1

Returns column 'LastName' of row 1

LastName[2]

or

LastName, 2

Returns column 'LastName' of row 2
1 Returns column 1 of row 1
1[1] Returns column 1 of row 1
1[2] Returns column 1 of row 2
/[1] or *[1] Returns the entire row 1 (all columns are returned, separated by commas)
/[2] or *[2] Returns the entire row 2 (all columns are returned, separated by commas)
/, 0 or *, 0 Returns the header row (all column names) when the CSV format has a header row; otherwise returns row 1
1, 0 Returns the name of column 1 when the CSV format has a header row

Reading the Header Row

Row index 0 is the header row. When Header Row is enabled on the CSV format, row 0 holds the column names and row 1 is the first row of data, so the data row indexes are the same whether or not the file has a header row.

// LastName,FirstName,MRN
// Smith,John,123
// Jones,Jane,456

var headerRow = message.getNode('/', 0);       // LastName,FirstName,MRN
var firstColumnName = message.getNode('1', 0); // LastName
var firstDataRow = message.getNode('/', 1);    // Smith,John,123

message.getNode('/', 0) returns the whole header row as text, joined with the configured separator and quoted according to the Use Quotes setting. To work with the column names individually, getHeaders returns them as a list instead:

var headers = message.getHeaders();  // ["LastName","FirstName","MRN"]

for (var i = 0; i < headers.size(); i++) {
  qie.debug('Column ' + (i + 1) + ' is named ' + headers.get(i));
}

Without a header row there are no column names to read

If Header Row is not enabled on the CSV format, message.getNode('/', 0) and message.getNode('/', 1) both return the first row of data, and getHeaders returns an empty list. Nothing errors: you silently get data where you expected column names, so confirm the format setting before treating row 0 as headers.

The header row is not counted as data. getRowCount, getCount('/'), and getAllNodes all skip it when Header Row is enabled, so getRowCount on the message above returns 2, not 3.

Troubleshooting Invalid column identifier

QIE throws MessageModelException: Invalid column identifier: '<path>' when it cannot resolve the column part of a CSV node path. Three causes account for almost every occurrence:

  1. No header matched the supplied name. Column-name lookup compares the path against each header value case-insensitively, with whitespace trimmed off the header before the comparison. A typo, a trailing space the parser already trimmed away on the path side, or a name that does not actually appear in the CSV all fall through to this error. Inspect the actual headers with message.getNode('/', 0) to see the header row (or open the message with View Formatted CSV / Shft+F5).
  2. Column index out of range. A numeric path like 7 resolves to column 7; if the CSV has fewer columns than that, the lookup fails. The same error fires.
  3. No header row. If the CSV format does not have a header row and the path is a name rather than an index, the error message includes a (header row not used) suffix. Either switch to index-based access or enable the header row on the CSV format.

For DB query results, the simplest fix when a name is unstable or contains characters that are awkward to type into scripts is to alias the SQL column to a clean identifier (SELECT some_col AS providerResource), the alias becomes the CSV header. For data that arrives as CSV from an external source, column-index access (message.getNode('3')) is a reliable fallback when the header text varies.