Using script how to export notes document, Response and Response to Resposne in Other database

Hi I have database A with Forms as document, response and response to response documents. I want to export those documents to other notes database B that only have document and Response( No resposee to response) document. Field on both database are different i.e I have to map field from database A of documents to fields from database B of documents. Not sure how.

Now question is how using Lotus script I can export documents from databae A to database B with same doucment relatioship as in database A i.e child parent relationship.

I really appreciated, if someone give me sample code.

Subject: Look at the MakeResponse method of the NotesDocument class

When you create your documents in database B you can use that method to create the same hierarchy as in database A.

Subject: I think, I did not explain clearly

In database A, I have Main document and response document. I.e

AA ( Main doucment, Form A)

AAa (Response document)

AAb (Response document)

AAc (Response document)

Database B, I have Form type document and response document, but field in document and response in database B are different then in database A.

Now I need a script map fields in main form in database A to map main form in database B and same with response and then export documents and response documents from database A to database B.

Thanks

Lisa

Subject: See other response…

Check my response here: http://www-10.lotus.com/ldd/nd8forum.nsf/0/0e03fa1491c1459385257a7600016f87

The easiest is to loop through the documents using recursion. If you define the field mappings using a list, it will be very easy to convert.

For example, if the field in form A is named ‘FirstName’ but in form B is ‘NameGiven’, you would map it like this:

field(“FirstName”) = “NameGiven”

Then you would have code like this:

set docB = New NotesDocument(dbB)

docB.Form = “FormName”

ForAll i in docA.Items

Call docB.ReplaceItemValue(i, docA.GetItemValue(ListTag(i)))

End Forall

Call docB.Save(True,True)

Something like that. Not very complicated.

Subject: Getting error Parent and Resposne document must be in same database

Hi I used one agent which copy some of the field info from the parent document and copy to other database and now I am using the following agent which copy the response docment but makeresponse I as getting above error.

Sub Initialize

Dim Session As New NotesSession

Dim Flddb As NotesDatabase

Dim FldDoc As NotesDocument

Dim ParentDoc As NotesDocument

Dim ImpDoc As NotesDocument

Dim View As NotesView

Dim Flddc As NotesDocumentCollection

Dim dcDoc As NotesDocument

Dim ChildDoc As NotesDocument

Dim uiws As New NotesUIWorkspace

Dim resp As Variant



Set Flddb=session.CurrentDatabase

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

Call FCRdb.Open(Flddb.Server, "TDAA\FCR2012-v2.NSF")

If Not( FCRdb.IsOpen) Then

	Messagebox (" Not able to find FCR database")

End If



Set collection = Flddb.UnprocessedDocuments

Set  FldDoc = collection.GetFirstDocument()



While Not(FldDoc Is Nothing)

	

	If FldDoc.Form(0)="CTRL"  Then

		'Get list of Cycle doucments

		resp = uiws.PickListStrings(PICKLIST_CUSTOM ,False, FCRdb.Server,FCRdb.FilePath,"ExportedParent","Choose a Cycle document", "Choose a Cycle document for this Control.",2)

		If Not Isempty (resp)  Then

'Get Parent document

			Set ParentDoc = FCRdb.GetDocumentByUNID(resp(0))

		'	Set FldDoc = FCRdb.GetDocumentByUNID(FldDoc.UniversalID)

		' Create Control document as response of Cycle document

			Set ChildDoc = Flddb.CreateDocument

			With ChildDoc

				.form = "fmControlDoc"		

				.ControlNum = FldDoc.DocIndex 

				.ControlDesc = FldDoc.CTEC

				.ControlType = FldDoc.ITDependent

				.ControlClassification = FldDoc.ControlDesc

				.ControlFreq = FldDoc.ctrlfrequency

				.ControlOwner = FldDoc.ActivityOwner

				.Exported="Yes"

				.MakeResponse ParentDoc

				.Save True, True

			End With

		End If

	End If

	Set  FldDoc=collection.GetNextDocument(FldDoc)

Wend

End Sub

Thanks for help

Lisa

Subject: The error message says it all…

…which is surprising given the often cryptic messages that Lotus Notes can dish up. According to your code ParentDoc is a document in the FCRdb database and ChildDoc is a document in the Flddb database. They have to be in the same database.

Subject: Why two agents?

You could easily do that in one agent. Pseudo code below:

'*** List of field names with

'*** source names as list tag

fieldname(“SourceField1”) = “TargetField1”

fieldname(“SourceField2”) = “TargetField2”

etc

Set sourceDB

Set targetDB

Set view = sourceDB.GetView(“LookupMainDocs”)

Set sourceDoc = view.GetFirstDocument

Do Until sourceDoc Is Nothing

'*** Create new main doc in target db

targetDoc = New NotesDocument(targetDB)

Call targetDoc.ReplaceItemValue(“Form”,“TargetFormName”)

'*** Loop thorugh all fields and copy values

'*** to corresponding fields in target doc

ForAll i In sourceDoc.Items

Call targetDoc.ReplaceItemValue(fieldname(i.Name), i.Value)

End ForAll

'*** Mark as archived and save

Call sourceDoc.ReplaceItemValue(“Exported”,“Yes”)

Call sourceDoc.Save(True,False)

Call targetDoc.Save(True,False)

'*** Get all responses

Set responseCol = sourceDoc.Responses

set sourceResponse = responseCol.GetFirstDocument

Do Until responseCol is Nothing

targetResponse = New NotesDocument(targetDB)

Call targetResponse.ReplaceItemValue(“Form”,“TargetResponseFormName”)

'*** Loop thorugh all fields and copy values

'*** to corresponding fields in target doc

'*** just like above

Call targetResponse.MakeResponse(targetDoc)

set sourceResponse = responseCol.GetNextDocument(sourceResponse)

Loop

Set sourceDoc = view.GetNextDocument(sourceDoc)

Loop

Change values of fields, etc as required.

You probably want two lists of field names, one for the main document and one for the response documents.

Subject: .

I am not sure if I understand one detail… When you copy the documents to database B, do you want the documents there to have response-to-response just like in database A, or do you want to flatten the document structure?

If you want to keep the same structure as in database A, that’s easy.

Just write a recursive function. This function will copy the documents from database A to database B, while remapping the fields. Then use doc.MakeResponse to make the newly created documents in database B responses to the correct document.

What I would do for the field mapping is to create a list of strings, with the field name in database A as list tag, and the fieldname in database B as the value.

If you use the same field name on different forms in database A, but want them to map to different fields in database B, you adding a layer of complexity, but nothing impossible.

You could create a Class, containing the list of strings/field names. Then you create one instance of this class for each form.

Then it is easy to do a ForAll in doc.Items and process all fields, copying the values to the new document you created in database B, using the correct fieldname.