Duplicating Records with Line items

Hi,
I need to duplicate a record that has many related records in a different table,
i.e. One invoice has many line items that are related. I know this probally has been done many times before, but some help would be appreciated.

here it is : http://forum.servoy.com/viewtopic.php?t … =duplicate

Hi,

here is a Global method (duplicateRecord) implementation:

Code:
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:

Code:
globals.duplicateRecord(foundset, new Array(‘parent_to_child’,‘parent_to_child2’));

Works like a treat, thank you so much, I am now duplicating parent and child records perfectly.

If I would now like to open a new form showing the newly duplicated record how would I do that??

As Always, Thankyou for all your help

ah yes, that’s a good one!

will have to look into my code, how I did that!
just a moment.

got it, just add this last line:

foundset.selectRecord(dup.yourPKcolumn)

hope this helps

Hi,
I’m sorry to be a dummy but where do I add this code?

foundset.selectRecord(dup.yourPKcolumn)

got it, just add this last line:

:lol: