Two similar scripts, one works one doesnt

Script that works:

var imgUrls = data.extract('customPhotoUrl', 0).trim() ;
var row;
var fileName, fileNameArr;
var return_val = '';

if (!imgUrls){
	return_val = "None"
}
else if(imgUrls.includes("~"))
{
	var urlArray = imgUrls.split("~")
	for( let url in urlArray)
	{
		row = record.tables.img.addRow();
		fileNameArr = urlArray[url].split("/");
		fileName = fileNameArr[fileNameArr.length - 1];
		record.tables.img[row].set({imgURL : fileName});		
	}
	return_val = "Multiple"
} else {
	row = record.tables.img.addRow();
	fileNameArr = imgUrls.split("/");
	fileName = fileNameArr[fileNameArr.length - 1];
	record.tables.img[row].set({imgURL : fileName.toString()});		
	return_val = "Single"
}
return_val;

Script that doesn’t work:

var letterText = data.extract('customMessage', 0).trim() ;
var row;
var return_val = '';

if (!letterText){
	return_val = "None"
}
else if(letterText.includes("<br>"))
{
	var textArr = letterText.split("<br>")
	for( let textIndex in textArr)
	{
		row = record.tables.letterArr.addRow();
		record.tables.letterArr[row].set({textRow : textArr[textIndex]});		
	}
	return_val = "Multiple"

}else{
	row = record.tables.letterArr.addRow();
	record.tables.letterArr[row].set({textRow : letterText});
	return_val = "Single"
}
return_val;

For some reason, the second script is erroring when calling “row = record.tables.letterArr.addRow();” of “Cannot call method “addRow” of undefined.”

Additionally, this is only on some data records, others seem to work just fine. I’m not sure how the data could be affecting this as this script is the only piece of the data mapper that interacts with the “letterArr” table.

I would think it depends on how the letterArr table was defined in your data model.
Was it defined implicitly (by using an extract step inside a loop) or did you explicitly define it in the data model?

Both letterArr and img are both defined in the data model

Currently no loops are being used in the datamapper

I’ve recreated a similar DM Config here using your exact script and can’t seem to replicate the issue.
multiline.OL-datamapper (3.8 KB)

What’s special about the records that fail in your data?

If you can’t find the cause of the issue, you can send me your DM config via private message (I am an OL employee) and I’ll be happy to take a look at it.

As a follow up for everyone:

@SamSorenson sent me his configuration file and I was able to confirm that the issue he describes is due to a known problem in the application (internal reference SHARED-91030).

In short, the DataMapper is unable to perform addRow() operations on more than a single table per record, when those tables were added explicitly via the data model. If the tables are added implicitly through an Extract Step, then the problem disappears. Note that there are also other circumstances that can trigger this issue, but for the sake of clarity, let’s just focus on the ones at hand.

@SamSorenson: this explains why some of your records records ran into the issue (those that updated both the letterArr and img tables) while others worked just fine (those that updated either the letterArr or the img table). It doesn’t matter in which order the tables are updated. As soon as two of them use the addRow() method, the issue occurs on the second one.

So the workaround, for now, is to make sure that an Extract Step creates the tables with at least one record in them. The script that runs later can then use a simple condition to use set() for the first table row, and addRow() for the subsequent ones.

The good news is that I was able to confirm that in the upcoming OL Connect 2024.1 version (scheduled for a May release), the issue has been addressed.