Reputation: 403
I would like to copy note item from one note document to the other using Java below is the my lotus script version of what i want to achive in Java
Sub CopyItem(FromDoc As NotesDocument, ToDoc As NotesDocument, itemName As String)
Dim FromItem As NotesItem
Dim ToItem As NotesItem
If Not (FromDoc.Hasitem(itemName)) Then Exit Sub
Set FromItem = FromDoc.GetFirstItem(itemName)
If Not ToDoc.hasitem(itemName) Then Set ToItem = ToDoc.CreateItem(itemName)
ToItem.Values = FromDoc.Values
End Sub
I have tried the below:
public static void copyAnItem(Document FromDoc, Document ToDoc, String sItemName){
Vector<String> FromItem = new Vector<String>();
Vector<String> ToItem = new Vector<String>();
if(!FromDoc.hasItem((itemName))){
return;
}
FromItem = FromDoc.getItemValue(itemName);
if(!ToDoc.hasItem(sItemName)){
ToItem.add(itemName);
}
ToItem.addAll(FromDoc);
}
Upvotes: 1
Views: 368
Reputation: 30970
public static void copyAnItem(Document fromDoc, Document toDoc, String itemName){
try {
if(fromDoc.hasItem(itemName)) {
toDoc.copyItem(fromDoc.getFirstItem(itemName));
}
} catch (NotesException e) {
// your exception handling
}
}
You can get the whole item including all properties from fromDoc with getFirstItem and can copy it to toDoc with copyItem in just one line of code.
Upvotes: 3
Reputation: 449
public static void copyAnItem(Document FromDoc, Document ToDoc, String sItemName){
if(FromDoc.hasItem(sItemName)){
ToDoc.replaceItemValue(sItemName, FromDoc.getItemValue(sItemName));
}
}
It won't work with Authors or Readers items. Better the Knut solution :)
Upvotes: 1