Copying response documents to another database

Hello there,I am trying to copy a parent document and all it’s response documents to another database. I am trying to to this through the notes client.

I have a view and when I select the parent document and click a transfer action, only the parent document and the first response document is transferred to the other database. No other response documents are sent. this is the lotusscript behind the transfer action button. Thank you

Sub Initialize

Dim session As New notessession

Dim thisdb As notesdatabase

Dim dc As notesdocumentcollection

Dim doc As NotesDocument

Dim dcResponses As NotesDocumentCollection



Dim otherdb As New NotesDatabase( "", "" )

Call otherdb.Open( "server1", "trackerk.nsf" )



Set thisdb = session.currentdatabase

Set dc = thisdb.unprocesseddocuments



For n = 1 To dc.count

	Set doc = dc.getnthdocument(n)

	doc.OriginalUNID = doc.UniversalID

	Call doc.Save(True, False)

	Set newDoc = doc.CopyToDatabase(otherdb)

	

	

	

	'transfer doc children, if any

	If doc.Responses.Count > 0 Then

		Set dcResponses = doc.Responses

		For nResp = 1 To dcResponses.Count

			Set doc = dcResponses.getnthdocument(n)

			doc.OriginalUNID = doc.UniversalID

			Call doc.Save(True, False)

			Call doc.CopyToDatabase(otherdb)

		Next

	End If

	

Next



		'notify the user

Set tmpMailDoc = thisdb.CreateDocument

tmpMailDoc.SendTo = "john smith"

tmpMailDoc.Subject = "New document requires your attention"

Set rtitem = New NotesRichTextItem( tmpMailDoc, "Body" )

Call rtitem.AppendText("Please review this document.  ")		

Call rtitem.AppendText("Open the document by clicking on the following link: ")

Call rtitem.AppendDocLink( newDoc, "New document" )



Call tmpMailDoc.Send(False)





Messagebox "Transfer sent",64,"Document status"

End Sub

Subject: copying response documents to another database

Don’t you think like n should be replaced with n Rep in the below code.

For nResp = 1 To dcResponses.Count

Set doc = dcResponses.getnthdocument(n)

doc.OriginalUNID = doc.UniversalID

Call doc.Save(True, False)

Call doc.CopyToDatabase(otherdb)

Next

End If

Best Regards

Vinay

Subject: copying response documents to another database

Hi Linda,

When u r saving the Responses on other database , try using MakeResponse method of NotesDocument. This is required if as the UNID of the document changes when copied to other database.

Also, try debugging the code while u run the LS , and check for the no of docs returned.

HTH

Tom

Subject: copying response documents to another database

Linda, I took the reminder from Calvin, and I wanted to use this as an excercise for myself. What I came up with was the following:

==========================

Dim s As New notessession

Dim thisdb As notesdatabase

Dim dc As notesdocumentcollection

Dim doc As NotesDocument, child As NotesDocument, newDoc As NotesDocument, newChild As NotesDocument

Dim responses As NotesDocumentCollection



Dim otherdb As New NotesDatabase( "", "" )

Call otherdb.Open( "server1", "trackerk.nsf" )



Set thisdb = s.currentdatabase

Set dc = thisdb.unprocesseddocuments



If dc.Count<1 Then

	Msgbox "You must select at least one document to transfer.  Please try again."

	Exit Sub

End If



Set doc = dc.GetFirstDocument



Do While Not (doc Is Nothing)

	doc.OriginalUNID = doc.UniversalID

	Call doc.Save(True, False)

	Set newDoc = doc.CopyToDatabase(otherdb)				

	'transfer doc children, if any

	If doc.Responses.Count > 0 Then

		Set responses = doc.Responses

		Set child = responses.GetFirstDocument 'get handle on child doc in source db

		Do While Not(child Is Nothing)

			child.OriginalUNID = child.UniversalID

			Call child.Save(True, False)				

			Set newChild = child.CopyToDatabase(otherdb)

			Call newChild.MakeResponse(newDoc )			

			Call newChild.Save(True,False)			

			Set child = responses.GetNextDocument(child)

		Loop

	End If

	Set doc = dc.GetNextDocument(doc)

Loop			

'notify the user

Set tmpMailDoc = thisdb.CreateDocument

tmpMailDoc.SendTo = “john smith”

tmpMailDoc.Subject = “New document requires your attention”

Set rtitem = New NotesRichTextItem( tmpMailDoc, “Body” )

Call rtitem.AppendText("Please review this document. ")

Call rtitem.AppendText("Open the document by clicking on the following link: ")

Call rtitem.AppendDocLink( newDoc, “New document” )

Call tmpMailDoc.Send(False)

Messagebox “Transfer sent”,64,“Document status”

==========================

Subject: RE: copying response documents to another database

Thank you so much for this and to everyone else who replied. It works great.