CopyToDocument Not Working as advertised

I’m running a local server/client environment w/ 6.5.1. I’m trying to copy a document and it’s responses from one database to another database on the same server. I also need to then copy the newly created documents/responses back to the first database (ping-ponging back and forth). Using .CopyToDatabase gives sporadic results - i.e. it works the first copy from a.nsf to b.nsf. However when going from b.nsf to a.nsf or the second time of a.nsf to b.nsf, the method creates the main document correctly but the responses end up on a different main document even though the docid of the new/second main document is being returned correctly. As you might be able to tell from the code below, I had to call .CopyToDatabase, get the unid and create a brand new notesdocument in order for the code to work.

WHY! WHY! WHY! WHY! WHY! WHY! WHY! WHY!

This has cost me a lot of time chasing what appears to be a bug not to mention the frustration.

Can someone tell me if I was doing something wrong? I did search this forum for similar posts but nothing appeared to be quite the same.

The commented code is what I had tried before and didn’t work.

Set docParentR1 = docParent.CopyToDatabase( db )

Print “copy…” & docParentR1.UniversalID

'Set docParentR = Nothing

Set docParentR = db.GetDocumentByUNID( docParentR1.universalid )

'Set vw = db.GetView( “pcnrevision” )

'Call vw.Refresh

'Set docParentR = vw.GetDocumentByKey( docParent.pcn(0) & Cstr( docParent.revision(0) ))

Print “lookup…” & docParentR.UniversalID

Set dc = docParent.Responses

If dc.count > 0 Then

…Set doc = dc.getfirstdocument

…While Not( doc Is Nothing )

…Set docChildR = doc.copytodatabase( db )

…Call docChildR.MakeResponse( docParentR )

…Call docChildR.Save(True, True, True )

…Set docChildR = Nothing

…Set doc = dc.getnextdocument( doc )

…Wend

End If

Subject: CopyToDocument Not Working as advertised

Here’s how I have used it…it worked fine.

Dim session As New NotesSession

Dim db As NotesDatabase

Dim db2 As New notesdatabase("servername", "feedback.nsf")  

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim owner As notesitem



Set db = session.CurrentDatabase

Set db2 = New notesdatabase("servername", "feedback.nsf")

Set dc = db.Unprocesseddocuments



For j = 1 To dc.Count

	Set doc = dc.GetNthDocument(j)

	Set owner = doc.replaceitemvalue ("SendTo", "Kracker Muffin")

	Call doc.copytodatabase(db2)

	

	Call doc.Save(False, True)

Next

Subject: RE: CopyToDocument Not Working as advertised

Thanks for the help Michael.

The problem I’m experiencing is with the form of .CopyToDatabase that is supposed to return a handle to the new document. My code does copy the document but when I do the following:

newDoc = curDoc.CopyToDatabase( db )

Something is returned into newDoc. However, when I try to make another document a response to newDoc, its as if newDoc becomes a different document since that’s where the responses show up. The UNID for newDoc matches the actual document’s UNID.

To be able to copy the documents over and make them a response, I have to copy the parent document, get a brand new handle on the parent document into a different NotesDocument object and then use that in child.MakeResponse( newParent ).

The .CopyToDatabase, at least in what I’m doing, does copy the document but doesn’t return the new document correctly.