How to create a duplicate record?

Questions, tips and tricks and techniques for scripting in Servoy

How to create a duplicate record?

Postby joe26 » Tue Dec 12, 2017 7:41 pm

I cannot get a duplicate record except from the last item.

The various steps either pulls in the wrong record for duplication or fails to create a duplicate record.

I really don't see what I'm missing.

thanks!
--Joe.

//This fails to provide a record for later editing
var newRecIdx = newRec.foundset.getRecordIndex(newRec);//newRec is the record to be duped
newRec.foundset.setSelectedIndex(newRecIdx); //this is not form-based, but added due to frustration...
newRecIdx = newRec.foundset.duplicateRecord();
newRec = newRec.foundset.getRecord(newRecIdx);//other variables have been used beside newRec

//This fails to provide a record for later editing
//databaseManager.saveData(newRec); //Doesn't work here either
var newRecIdx = tableFS.getRecordIndex(newRec);
var dupIdx = tableFS.duplicateRecord(newRecIdx);
newRec = tableFS.getRecord(dupIdx);

//This is the ONLY iteration that was actually sucessful for duplicating a record
var oldRec = newRec;
var newIdx = tableFS.newRecord(false);//newRec.foundset.duplicateRecord(false);
newRec = tableFS.getRecord(newIdx);
for (var item in oldRec){newRec[item] = oldRec[item]}
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm

Re: How to create a duplicate record?

Postby erdione » Wed Dec 13, 2017 12:12 am

Fabrice
erdione
 
Posts: 112
Joined: Thu Feb 01, 2007 1:19 pm

Re: How to create a duplicate record?

Postby joe26 » Wed Dec 13, 2017 10:54 am

Easy is what I thought when I wrote it some time ago, but deeper analysis of the created records and their necessary contents varied.

The copyMatchingFields is working well, however.

edit:
What might be happening is attempting to create a duplicate of a new record.
Could there be a problem with duplicating a new foundset record which has not yet been saved to the database with a databaseManager.saveData(record) call?

Thanks!
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 8 guests

cron