Problem using CopyToDatabase

Hello,

I am a little new at LS and hoping that someone can help…

I am saving a document on the web using a button consisting of some JS to verify data in required fields, followed by a “document.forms[0].submit()” command.

From there I am using a LS agent called from WebQuerySave. The agent should verify that the document has been saved, then copy it to another database on the same server. If the copy is successful, set a field in the original document to flag it as such. Here is the LS being used in my agent…

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim db2 As Notesdatabase

Dim doc As NotesDocument

Dim newdoc As NotesDocument

Dim checkdoc As NotesDocument

Dim view2 As NotesView

Dim Trans_DocID As String



Set doc = session.DocumentContext

Set db = session.CurrentDatabase

Set db2 = New NotesDatabase( "" , "fleet-tt.nsf" )



' If current document has been saved, copy it to Fleet_TT.nsf, otherwise save then copy

If doc.IsNewNote Then

	Call doc.Save(True, False)

	Call doc.CopyToDatabase(db2)

Else

	Call doc.CopyToDatabase(db2)

End If



' Verify copy was sucessful, then set flag for remove agent

Set view2 = db2.GetView( "WebTransactions" )

Set checkdoc = view2.GetDocumentByKey( Trans_DocID, True )



If checkdoc.Trans_DocID <> ""  Then 

	doc.Copy_Status = "Copy Successful"

	Call doc.Save(True, False)

End If

End Sub

The problem is that while the original document passes verification and saves, the copytodatabase command fails… As a simple test I have added a button to the form that just executes an @Command([FileSave]) to bypass my verification process. Using this method I have found that I must hit the button twice before the copytodatabase command executes, however the original document was saved on the first press.

I’ve searched the forum extensively, but have not found a solution. Can anyone see where I am going astray?? Please help.

Thanks, Steve

Subject: Problem using CopyToDatabase…

You should not explicity save a document in the WebQuerySave agent. That could cause a host of problems.

Can you instead have a scheduled agent that runs, checking for new documents, and creating a copy of them at that point?

Subject: RE: Problem using CopyToDatabase…

Thanks Rellim, I was not aware of that, and will definitely keep this in mind as I proceed!

I could use a scheduled agent, but the immediacy is such that the document must be available in the remote database as soon as it is saved. Creating a new document and using CopyAllItems might be a better alternative to my current method.

Thanks so much for your quick response!

Steve

Subject: You could try:

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim db2 As Notesdatabase

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Dim view2 As NotesView

Dim ret



Set doc = session.DocumentContext

Set db = session.CurrentDatabase

Set db2 = New NotesDatabase( "" , "fleet-tt.nsf" )



Set doc2 = db2.CreateDocument

Call doc.CopyAllItems(doc2, True)

ret = doc2.Save(True, False)



If ret Then 

	doc.Copy_Status = "Copy Successful"

End If

End Sub

Subject: RE: You could try:

Thanks Bill. Yours is a good alternative, and one that I was considering from a drop back and punt standpoint.

I’ve spent so much time trying to work the bugs out of the CopyToDatabase method, and will probably back-track to it later just to understand where I went wrong.

Thanks again for your help!

Steve