here is a Global method (duplicateRecord) implementation:
var fs = arguments[0];
var relatedFsArray = arguments[1];
// Duplicate master record.
var dup = fs.getRecord(fs.duplicateRecord(false,false));
// save is needed if DB_IDENT sequence is used!!
currentcontroller.saveData();
for(var k=0;k<relatedFsArray.length;k++)
{
var related = fs[relatedFsArray[k]];
for(var i=1;i<=related.getSize();i++)
{
var relatedOriginal = related.getRecord(i);
var relatedDub = dup[relatedFsArray[k]].getRecord(dup[relatedFsArray[k]].newRecord(false,false));
databaseManager.copyMatchingColumns( relatedOriginal, relatedDub);
}
}
currentcontroller.saveData();
which can be called from any form method like this:
globals.duplicateRecord(foundset, new Array('parent_to_child','parent_to_child2'));
So give the global method the foundset and then an array with the names (as string!!) of all the related foundsets you also want to duplicate.
This is pretty much the fasted way to duplicate related foundsets, because calling duplicate on the relatedFoundset is slow because you first add the record to the relatedFoundset itself and then move it out of that relatedfoundset by updating the (f)key column.
You need the final of 2.1.2 for this piece of code because the i fixed a bug in duplicateRecord call, because it was returning an index that was 1 to small. So to test this code you have to add one by duplicateRecord:
var dup = fs.getRecord(fs.duplicateRecord(false,false)+1);