How to create a duplicate record?

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]}

you should be able to do it easily

Or create new record and then copy matching fields from old record to new record

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!