Copying document to folder in another database

I am trying to take an incoming email and save a copy in a folder in a second mail database. I have code which looks like it should work. It does get saved in second database, but not in the folder. I also tried to add an item to the copy. The item gets saved in the original, but not the copy. This agent runs before new mail arrives. Any ideas what is going wrong?

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim db2 As NotesDatabase

Dim destDoc As NotesDocument



Set db = session.CurrentDatabase

Set doc=session.DocumentContext

Set db2 = New NotesDatabase("mailserver", "mail\seconddatabase.nsf")



Call doc.AppendItemValue("SecondaryDomain", "domanname.net")

Set destDoc = doc.CopyToDatabase(db2)

Call destDoc.AppendItemValue("SecondaryDomain", "domanname.net")

Call destDoc.PutInFolder("Folders\domanname.net", True) 

Call destDoc.Save(True, False)

Call doc.Save(True, False)

Subject: try this

Dim session As New NotesSessionDim db As NotesDatabase

Dim doc As NotesDocument

Dim db2 As NotesDatabase

Dim destDoc As NotesDocument

Set db = session.CurrentDatabase

Set doc=session.DocumentContext

Set db2 = New NotesDatabase(“mailserver”, “mail\seconddatabase.nsf”)

Call doc.AppendItemValue(“SecondaryDomain”, “domanname.net”)

Set destDoc = doc.CopyToDatabase(db2)

Call destDoc.AppendItemValue(“SecondaryDomain”, “domanname.net”)

;save destdoc first then putinfolder

Call destDoc.Save(True, False)

Call destDoc.PutInFolder(“Folders\domanname.net”, True)

Call doc.Save(True, False)

Subject: re: try this

Thank you for your reply. I tried it and it still did not work. However, I discovered a rule that had to be conflicting with the agent, because after I disabled it, all worked as expected.

Best regards