So I have the following issue: I have a Foundset with a bunch of records, and I'd like to (deep) copy them to a new location, including all values but without the IDs. What's the best way to do this?
Asked
Active
Viewed 40 times
1
-
Please share what code you have already tried. – lucuma Apr 16 '13 at 14:18
1 Answers
1
If you want to do an deep copy of an foundset you need the follow steps:
- Create an empty foundset over
retrieveOrCreateFoundset()
- iterate over all records of the foundset, that should copied to a new one
- get the dataProviders with something like
rec.dataprovider()
- get the value of each dataprovider on a record
rec.value()
- be sure that the uuid dataprovider isnt copy to the new Record
- set the values to a the new record over the dataproviders
- persist the changes
Full code example would be:
var vMobileController = plugins.iBizClientWebService.mobileController();
var vFoundset = vMobileController.currentFoundset();
var vDatabaseManager = vMobileController.dataManager();
var copyFoundSet = vDatabaseManager.retrieveOrCreateFoundset("<datasource>:<label>");
for (var index = 0; index < vFoundset.size(); index++) {
var rec = vFoundset.record(index);
var loc = copyFoundSet.newRecord();
var newRecord = copyFoundSet.record(loc);
var allDataproviders = rec.dataprovider();
for(var i=0;i<allDataproviders.length;i++)
{
var dataProvider = allDataproviders[i];
var dataValue = rec.value(dataProvider);
if(dataProvider != "attribute_id")
{
newRecord.setValue(dataProvider, dataValue);
}
}
}
copyFoundSet.saveData();

Weptun
- 158
- 4