public void copyRecord(){
ObjectDB obj = getGrant().getTmpObject("MyObject");
if(obj.select(targetRowId)){// targetRowId is the row id of the record you want to override
for(ObjectField f : getFields()){
if(!f.isTechnicalField()){
String val = f.getValue();
String name = f.getName();
obj.setFieldValue(name, val);
}
}
//set document
obj.getField("myDocField").setDocument(getField("myDocField").getDocument(getGrant()));
obj.save();
}
}
Vous pouvez intégrer à votre code les éléments suivants (lorsque vous bouclez sur les attributs à copier) :
if(f.isMultiDocuments()){
DocumentDB copiedDocs = copyAndGetDocuments(this, f, getRowId(), targetRowId);
obj.getField(f.getName()).setDocument(copiedDocs);
obj.getField(f.getName()).setValue(""); // cross reference not used
}
Avec copyAndGetDocuments(...) comme suit :
private DocumentDB copyAndGetDocuments(ObjectDB obj, ObjectField f, String rowId, String targetRowId){
DocumentDB currentDocs = DocumentDB.getDocuments(obj, f, rowId);
DocumentDB newDocs = new DocumentDB(true); //instantiate a multi-doc DocumentDB object
if (currentDocs!=null) {
List<DocumentDB> list = currentDocs.getDocuments();
if (list!=null)
for (DocumentDB d : list){
try{
DocumentDB newDoc = new DocumentDB(null, d.getName(), d.getBytes(true), getName(), f.getName(), targetRowId); //create a new DocumentDB per document found in list
newDoc.setStatus(DocumentDB.STATUS_TO_UPLOAD);
newDocs.add(newDoc); //add to list of documents
}
catch(IOException e){
//handle IOException
}
}
}
return newDocs;
}