duplicate records

I would like to see a feature where we can duplicate a complete foundset, with just one statement and that this action is taken out on the server!

Now we have to loop thru the records, which can be (internet-client) rather SLOWWwww…

(Mostly we use this, to duplicate line-items, from a offer to an order and than to an invoice!)

In combination with the: databaseManager.getFoundSetUpdater(foundset)
this will be a VERY powerfull tool!

Is it possible?

ouch, good suggestion… Would love this too!

In Servoy 2.5 a relation will get an option “duplicate Related Records” so when you duplicate a record all child records will be duplicated (this will only work correclty on relations where the leftside from the relation is a sequence, otherwise the old parent will have the double amout of childeren)

Just to be sure: Is it possible to duplicate between different relations?

my offer-table has a relation to lineitems-table
my order-table has a relation to lineitems-table and
my invoice-table has a relation to lineitems-table

If I duplicate an offer to and order or an order to an invoice, I have to set/change another key-field too!

Do you get my idea?

between foundset will not be possible…with this feature
but moving a lineitem from an offfer to order to invoice only requires updating a flag instead of duplicate? (and all the 3 relations having a 2th key to the flag)

but moving a lineitem from an offfer to order to invoice only requires updating a flag instead of duplicate?

from an order to an invoice this is possible, but I do not want this from an offer to an order. Sometimes things changes, for example: a price of a lineitem. If I change this, I want the offer to stay intact!!
This is the reason, why I duplicate the lineitems!

Is it possible, with an other (new :) ) feature?

HJK:
but I do not want this from an offer to an order. Sometimes things changes, for example: a price of a lineitem. If I change this, I want the offer to stay intact!!

Maybe you could think of an offered_price and ordered_price column

HJK:
Is it possible, with an other (new :) ) feature?

You have to duplicate records and must set the new foreign key for each record, so looping is hard to avoid, suggestions are welcome…

just the first reminder when looping in 2.5
don’t use controller.recordIndex anymore for this but the syntax will now be this:

for(var i=1;i<=foundset.getSize();i++)
{
var record = foundset.getRecord(i);
record.dataprovider = XXXXX;
}

this is much much faster because the selection on the UI will not change.

WOW, this is really interesting stuff!
This would improve the performance a lot, because we use many loops.
Thanks for looking into this!

Is there any way this might be added sooner?

See Post: Duplicate Record and line Items - #11 by airmark - Classic Servoy - Servoy Community

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);

Thanks Johan!

This is perfect. Very fast.

About 4 seconds to duplicate 30 realted records containing 3 photos each (over 2 megs total).

Works great! Thank you very much.

After some more testing I find that the above method works well on a local area network, but is extremely slow over the internet. For example, with 350 related records to duplicate it takes about 10 seconds locally, but over a minute from a remote client.

Is this consistant with what others are experiencing?

Just a suggestion regarding duplication of records.

Jan Blok:
In Servoy 2.5 a relation will get an option “duplicate Related Records” so when you duplicate a record all child records will be duplicated (this will only work correclty on relations where the leftside from the relation is a sequence, otherwise the old parent will have the double amout of childeren)

Duplicating child records would be great, I will just point out an issue with ‘duplicating’.
The perfect duplication method would let us exclude some (a list) dataproviders in order to avoid for instance incorrect creation date, user and so on.
This could be done by method, off course, but think about the feature…