Moving data to a response document

Have a database that has a main document with two set of address fields in it…

address1, address2, city, state, zip…

and

paddress1, paddress2, pcity, pstate, pzip …

I need to move each address block to individually to a response document. .so that I wind up with 1 main document, and two address documents that are responses to the main doc.

Have 4,300 records, so obviously need to do this in an agent.

I realize it will probably have to be done in Lotussscript… but am novice at that, and not sure how to approach this problem.

Any help would be appreciated.

Thanks,

Subject: Moving data to a response document

Totally Untested.

Sub Initialize

    ' The Patented Regenold Response Creator



On Error Goto ErrHandle



Dim session As New NotesSession



Dim db As NotesDatabase

Set db = session.CurrentDatabase



Dim agentLog As New NotesLog("Regenold Response Creator")

Call agentLog.OpenFileLog( "c:\log.txt" )



Dim view As NotesView

Set view = db.GetView( "(Some Lookup View)" )



Call view.Refresh()



Dim doc As NotesDocument

Set doc = view.GetFirstDocument



If doc Is Nothing Then

	Goto Done

End If



While Not doc Is Nothing

	

	Dim item As NotesItem

	Dim errorFlag As Boolean

	errorFlag = False

	

	' Create Response A

	Dim docA As New NotesDocument( db )

	Call docA.MakeResponse( doc )

	docA.Form = "SomeForm"

	Set item = doc.GetFirstItem( "address1" )

	Call docA.CopyItem( item, "address1" )

	Set item = doc.GetFirstItem( "address2" )

	Call docA.CopyItem( item, "address2" )

	Set item = doc.GetFirstItem( "city" )

	Call docA.CopyItem( item, "city" )

	Set item = doc.GetFirstItem( "state" )

	Call docA.CopyItem( item, "state" )

	Set item = doc.GetFirstItem( "zip" )

	Call docA.CopyItem( item, "zip" )

	

	If docA.ComputeWithForm( True, False ) Then

		Call docA.Save( True, False )

	Else

		Error 101, "Response docA for doc " + doc.Title(0) + " did not save."

		errorFlag = True

	End If

	

	' Create Response B

	Dim docB As New NotesDocument( db )		

	Call docB.MakeResponse( doc )

	docB.Form = "SomeForm"

	Set item = doc.GetFirstItem( "paddress1" )

	Call docB.CopyItem( item, "paddress1" )

	Set item = doc.GetFirstItem( "paddress2" )

	Call docB.CopyItem( item, "paddress2" )

	Set item = doc.GetFirstItem( "pcity" )

	Call docB.CopyItem( item, "pcity" )

	Set item = doc.GetFirstItem( "pstate" )

	Call docB.CopyItem( item, "pstate" )

	Set item = doc.GetFirstItem( "pzip" )

	Call docB.CopyItem( item, "pzip" )

	

	If docB.ComputeWithForm( True, False ) Then

		Call docB.Save( True, False )

	Else

		Error 102, "Response docB for doc " + doc.Title(0) + " did not save."

		errorFlag = True

	End If

	

	' Remove original values

	If errorFlag <> True Then

		Call doc.RemoveItem("address1")

		Call doc.RemoveItem("address2")

		Call doc.RemoveItem("city")

		Call doc.RemoveItem("state")

		Call doc.RemoveItem("zip")

		Call doc.RemoveItem("paddress1")

		Call doc.RemoveItem("paddress2")

		Call doc.RemoveItem("pcity")

		Call doc.RemoveItem("pstate")

		Call doc.RemoveItem("pzip")

		

		If doc.ComputeWithForm( True, False ) Then

			Call doc.Save( True, False )

			Call agentLog.LogAction("Success: " & doc.Title(0))

		Else

			Error 103, "Doc " + doc.Title(0) + " did not save."

		End If

		

		errorFlag = False

		

	End If

NextDoc:

	Set doc = view.GetNextDocument(doc)

Wend



Goto Done

ErrHandle:

Print "Error" & Str(Err) & ": " & Error$

Call agentLog.LogAction("Error" & Str(Err) & ": " & Error$)

Resume NextDoc

Bail:

Call agentLog.Close

Print ""

End Sub

Subject: Moving data to a response document

  1. put your main documents in a sorted view2. create an agent that can be run on selected documents in view

  2. the agent can then use a NotesDocumentCollection obtained from Database.UnprocessedDocuments to get a handle on all the documents to be processed.

  3. loop through the document collection using for i = 1 to DocumentCollection.Count … Next i

  4. within the loop, set docMain = Documentcollection.GetNthDocument(i) so you have a handle on the current document being processed.

  5. Once you’ve got hold of docMain you can access the fields in it, so create another document and pull those fields into it:

set docResp = new notesDocument(Database)

docResp.address1 = docMain.address1 etc.

  1. then save the new response and make it a response to the main docuemnt

call docResp.MakeResponse(docMain)

call docResp.Save(true)

Then move on to the next one.

If you don’t understand the above, then a) read the designer help, and b) go on a training course