Friday, March 02, 2007

NotesNoteCollection + ExportDesignElement + NotesDXLImporter

Here, I try to explain you how we can change design document with Lotus Script.
For example you want to put a subformA from database1 to formA in database2.

1) So, firstly you must copy our subform from database1 to database2.
Dim nc As NotesNoteCollection
Dim doc As NotesDocument
Dim El As String
Dim nid As String, nextid As String
Dim i As Integer

Set nc = db.CreateNoteCollection(False)
Let nc.SelectSubforms = True
Call nc.BuildCollection

Set GetNoteElement = Nothing
Let nid = nc.GetFirstNoteId

For i = 1 To nc.Count
Let nextid = nc.GetNextNoteId(nid)
Set doc = db.GetDocumentByID(nid)
Let El = doc.GetItemValue("$TITLE")(0)
If El = “subformA” Then
Set GetNoteElement = doc
Let i = nc.Count
End If
Let nid = nextid
Next

...
And then copy to database2 as usual notesdocument.
...

2) This is main step. You must take a formA from database2 and export it, then take the content of export file and add to it

Dim s As New notessession
Dim stream As NotesStream
Dim content As String
Set stream = s.CreateStream
If Not stream.Open(filepath, "UTF-8") Then
Print "Not open"
Exit Sub
End If
If stream.Bytes = 0 Then
Print "Not content"
Exit Sub
End If

Let content = stream.ReadText()

If Instr(content, {wtInclude}) = 0 Then
Let content = Replace(content, {}, {})
End If

Call stream.Truncate
Call stream.WriteText(content)
Call stream.Close

3) Then you must import this file to database2.

I tested it on XP and 2000, and it worked.

No comments :