OL Learn

Extract from CSV using addrow

I’m trying to extract from csv file using datamapper script but when using addRow to extrac multiple tables found the following error “Cannot call method “addRow” of undefined”

var oneLine = data.extract(1,200,0,1,"").split("|");

var rec;
switch (oneLine[0]){
case “01”:
case “02”:
case “03”:
case “04”:
var index= record.tables.products.addRow({Number:oneLine[1],Description:oneLine[2],UnitPrice:oneLine[3],Ordered:oneLine[4],Shipped:oneLine[5],BackOrder:oneLine[6],Total:oneLine[7]})
case “05”:
var index1= record.tables.test.addRow({Number:oneLine[1]});


Hi @mkamel, welcome on our OL Learn forum!

Can you let us know please if the detail table “products” does exist in your Data Model? If so, please note that the addRow method can only add adds a record to an existing detail table.

Hi Marten,
kindly find the attached sample
and i’m testing to cerate two tables and set the data

test.OL-datamapper (4.8 KB)

Hi @mkamel, Thank you for sharing the Data Mapper.

I can see that the record table “test” does exist in the Data Model. I assume that, based on the shared Data Mapper, you cannot use the method “addRow” in one Repeat Step > Action Step when you try to add a row detail table “products” or detail table “test” in the same Repeat Step plus Action Step. Because I can see that the preview/result of typing “record.tables.test.” becomes “UniqueTag” instead of “Array” when you type this line of code after the following line of code has been executed (“Apply script”):

record.tables.products.addRow({Number: "123"});

For example:

record.tables.products.addRow({Number: "123"});

logger.info("record.tables.test: \"" + typeof record.tables.test + "\"");

Result: record.tables.test: "undefined"

//record.tables.products.addRow({Number: "123"});

logger.info("record.tables.test: \"" + typeof record.tables.test + "\"");

Result: record.tables.test: "object"

As stated in the online help for the addRow() method: “The detail table must already exist in the data model, otherwise the call fails.