Extract from CSV using addrow

Hi,
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”
https://help.objectiflune.com/EN/PlanetPress-connect-user-guide/2021.1/datamapper/API/Method_table_addRow.htm


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

var rec;
switch (oneLine[0]){
case “01”:
record.set({OrderNumber:oneLine[1],CustomerPO:oneLine[2],CustomerNumber:oneLine[3],Date:oneLine[4]});
break;
case “02”:
record.set({Company:oneLine[1],StreetAddress:oneLine[2],City:oneLine[3],State:oneLine[4],Country:oneLine[5],ZipCode:oneLine[6]});
break;
case “03”:
record.set({ContactFirstName:oneLine[1],ContactLastName:oneLine[2],ContactPhone:oneLine[3],ContactEmail:oneLine[4]});
break;
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]})
record.tables.products[index].set()
break;
case “05”:
var index1= record.tables.test.addRow({Number:oneLine[1]});
record.tables.test[index1].set()
break;

}

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.