Sidebar

Can I programmatically add entries to a Table?

0 votes
497 views
asked Mar 9, 2016 by brandon-w-8204 (33,170 points)
I need to add entries to a system variable type of table. Can this be done programatically in a channel.

1 Answer

+4 votes
 
Best answer

Any system variable can be updated via a mapping in a channel. For tables you have to treat it as one object and retrieve the entire table. Add the row and then set it back. 

1. Update the Table in the System variables to allow setVariable to update it.
Do this by checking the "Allow variable to be updated from scripts" on the System Variable

2. In a mapping retrieve the table and add a row. Example mapping below

//Retrieve the Entire table and parse as a CSV message model
var csvModel = qie.parseCSVString(qie.getVariable('testVariable1'));
//get RowCount to know what row to add the new Record
var rowCount = csvModel.getRowCount();
// Add new record to the csv Message model
csvModel.setNode('1[' + (1 + (rowCount*1)) + ']', 'new');
csvModel.setNode('2[' + (1 + (rowCount*1)) + ']', 'new');
//Update the system variable back with the new record added.
qie.setVariable('testVariable1', csvModel);
 
answered Mar 9, 2016 by brandon-w-8204 (33,170 points)
selected Feb 17, 2023 by amanda-w-3695
...