Record not being saved without controller.saveData()

We have come across an issue when moving larger amounts of data. We loop over a dataset like this:

for ( var i = 1 ; i <= dataset.getMaxRowIndex(); i++ )
{
	var tRecord = forms['t_' + tTable].foundset.getRecord(forms['t_' + tTable].foundset.newRecord(false, false));
	for ( var j = 1 ; j <= dataset.getMaxColumnIndex() ; j++ )
	{
		if (dataset.getColumnName(j) in tRecord) {
			tRecord[dataset.getColumnName(j)] = dataset.getValue(i, j);
		}
	}
}

This loop is called from another method for every relevant table (another loop). We noticed that we always have one record less than we should have. When debugging this, I even see the last record that gets created in that variable tRecord, but it never gets to the database. Issuing a controller.saveData() after the loop fixed the issue.

Thanks
Patrick

Hi Patrick

I have come across the exactly same problem some days ago. Also with smaller datasets ,-) As far as I could track it down the newRecord command issues a commit and with the last record there is now newRecord anymore and so it is not saved. Unless one uses controller.saveData() after the loop very inconsistent. If there is such implicit behaviour with some methods (as obviously with foundset.newRecord committing the record) I should have it listed in the docu. Otherwise these things are very time consuming to find out.
May be there is even more behind the whole thing!?

Best regards, Robert

patrick:
We have come across an issue when moving larger amounts of data. We loop over a dataset like this:

for ( var i = 1 ; i <= dataset.getMaxRowIndex(); i++ )

{
var tRecord = forms[‘t_’ + tTable].foundset.getRecord(forms[‘t_’ + tTable].foundset.newRecord(false, false));
for ( var j = 1 ; j <= dataset.getMaxColumnIndex() ; j++ )
{
if (dataset.getColumnName(j) in tRecord) {
tRecord[dataset.getColumnName(j)] = dataset.getValue(i, j);
}
}
}




This loop is called from another method for every relevant table (another loop). We noticed that we always have one record less than we should have. When debugging this, I even see the last record that gets created in that variable tRecord, but it never gets to the database. Issuing a controller.saveData() after the loop fixed the issue. 

Thanks
Patrick

I usually use controller.saveData(). Here I forgot. But the issue is absolutely a bug. Servoy should never “omit” a record after issuing a newRecord(), unless there is an error. I only use controller.saveData() so often because I use DB identities…

Hi Patrick

I agree with you but beside that I still don’t know exactly what store/save/commit mechanism is built into Servoy. For example, when I import data (from a file) into master - detail (1:n) tables, I have to first save the master record before I can via relationship add detail records (with Servoy seq no). That’s ok, but I had to find it out. I did not read anywhere anything about these basic handlings and that makes the entrance unnecessry difficult. I am missing some documentation about basic concepts of Servoy.

Best regards, Robert

patrick:
I usually use controller.saveData(). Here I forgot. But the issue is absolutely a bug. Servoy should never “omit” a record after issuing a newRecord(), unless there is an error. I only use controller.saveData() so often because I use DB identities…