Copytodatabase cannot copy response form?

Hi all,

Im doing an agent to copy a current document into same database. (web application). I need to copy the form and its related response form. But, what I get is, the main form is success copied but the response form only can copied one document. I have no idea to solve. Anyone can give me solutions?

Below is my agent:


Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As notesdocument

Dim view As NotesView

Dim vdoc As NotesDocument

Dim sview As NotesView

Dim sdoc As NotesDocument

Dim child As notesview

Dim childdoc As NotesDocument

Dim cdoc As notesdocument

Dim procStatusItem As NotesItem

Dim nobj As NotesName

Set db = session.CurrentDatabase

Set doc = session.DocumentContext

Set nobj = New NotesName(session.EffectiveUserName)

doc.copyFlag = “Yes”

Set procStatusItem = doc.GetFirstItem(“SCProcessStatus”)

remarks = “This Claim Form copied to another new Claim Form” & " by " & nobj.Common & " on " & Today() & " " & Time()

Call procStatusItem.AppendToTextList( remarks )

Call doc.Save(True,True)

Set view = db.GetView(“(AllHeaderView2)”)

Set vdoc = view.GetDocumentByKey(doc.SCEmpID(0)+doc.SCClaimNo(0),True)

Call vdoc.CopyToDatabase(db)

vdoc.SCStatus = “New”

vdoc.CurrLevelApp = doc.TotalApp(0)

vdoc.SubmitFlag = “”

vdoc.SCStatusDisp = “New”

vdoc.ApprovalStatus = “”

vdoc.Approver = “”

vdoc.SCAdjustMileageFlag = “”

vdoc.prevMileage = “”

vdoc.copyFlag = “”

Set seqview = db.GetView(“(SerialNo)”)

Set seqdoc = seqview.GetDocumentByKey(doc.SCEmpID(0),True)

If Not (seqdoc Is Nothing) Then

seqdoc.ClaimSerialNo = seqdoc.ClaimSerialNo(0) + 1

claimno = seqdoc.ClaimSerialNo(0) + 1

End If

Call seqdoc.Save(True, True)

vdoc.SCClaimNo = Year(Today()) & “-” & Format(seqdoc.ClaimSerialNo(0),“0000”)

vdoc.SerialNo = Val(seqdoc.ClaimSerialNo(0)) + 1

vdoc.SCProcessStatus = "Claim Copied from Claim No. " & doc.SCClaimNo(0) & " by " & nobj.Common & " on " & Today() & " " & Time()

vdoc.DateApplied = Today() & " " & Time()

vdoc.LastUpdateDateTime = Today() & " " & Time()

vdoc.LastUpdateName = session.EffectiveUserName

Call vdoc.Save(True,True)

Set child = db.getview(“(AllChildRejectedView)”)

Set childdoc = child.GetFirstDocument()

While Not (childdoc Is Nothing)

If childdoc.SCDEmpID(0) = doc.SCEmpID(0) Then

If childdoc.SCDClaimNo(0) = doc.SCClaimNo(0) Then

Call childdoc.CopyToDatabase(db)

childdoc.Approver = “”

childdoc.SCDStatusDisp = “New”

childdoc.SCDStatusADJ = “”

childdoc.prevAdj = “”

childdoc.SCDClaimNo = Year(Today()) & “-” & Format(seqdoc.ClaimSerialNo(0),“0000”)

childdoc.SCDStatus = “New”

childdoc.SCDAdjustment = “”

Call childdoc.Save(True,True)

End If

End If

Set childdoc = child.GetNextDocument(childdoc)

Wend

End Sub


Thank You.

Subject: RE: copytodatabase cannot copy response form??

I don’t understand what you’re saying it does wrong (“can only copy one form”? what?) but CopyToDatabase works just fine with any kind of document. Response documents might be harder to see in a view because they are responses to something, and the $REF field in the copied document might give the UNID of a document that doesn’t exist in the new database. See MakeResponse method.

Subject: copytodatabase cannot copy response form??

Looks to me like you are editing the original document in the original database:

Call childdoc.CopyToDatabase(db)

childdoc.Approver = “”

If you do this, it is possible that the original document is no longer a part of the “child” view (that is, you’ve changed a value that is used in the select statement of the view), and therefore child.GetNextDocument(childdoc) can’t find the next document.

If you want to edit the original document, use a temporary document to store the next document in the view, e.g.:

call childdoc.CopyToDatabase(db)

set tempdoc = child.GetNextdocument(childdoc)

<…edit childdoc…>

set childdoc = tempdoc

Wend

If your intention is to edit the new copy, use:

Set newdoc = childdoc.copytodatabase(db)

newdoc.Approver=“”

<…etc…>

Hope this helps.