Notes to SharePoint Migration - Part2

CautionThis series of articles is written for those who already having some acquaintance with Lotus Notes and SharePoint and involved/to be involved in the data migration to SharePoint.


Extract Attachments


In some LN applications, response records might hold the attachments where as you need to migrate the contents only to a custom list and not to a discussion board (meaning, you cannot set the relation between parent & children records after migration into SharePoint application). So in the end, you left with migrated main data without the attachments from the response records. User may demand for main data migration along with response record attachments (only). In such case, you may need to work on the LN application to move the attachments of response records to the respective main records well before start of the migration.


Here I have included the LN script program to extract the attachments from response records and move to the parent record.


Create a new agent and paste the below script and run. Change the drive name, file name according to your need. 


Also you could tweak this program to copy the Rich Text (RT) contents from response record to main record. Also, this same script could slightly changed to extract the  document attachment (non-RT field) from the LN document and move it to a new RT field in the same document. Migration facilitator tool (in general) could understand the files attached in the RT fields than the files attached with the LN document itself.


Lotus Script to extract attachment from Response records and move it to parent record:



Extract Attachments (Agent) : Initialize
'Attachprocess:
Sub Initialize
Dim session As New notessession
Dim db As NotesDatabase
Dim vw As NotesView
Dim attachmentvw As NotesView
Dim file_path As String
Dim object As NotesEmbeddedObject
Dim object1 As NotesEmbeddedObject
Dim doc As notesdocument
Dim coll As notesdocumentcollection
Dim attachmentdoc As notesdocument
Dim attachmentNextdoc As notesdocument
Dim RT As NotesRichTextItem
Dim filen As Integer
Dim count As Integer
filen=Freefile()
Open "C:/AttachmentProcessLog.txt" For Output As filen
Set db=session.CurrentDatabase
Set vw=db.GetView({})
Set attachmentvw = db.GetView({})
Set doc=vw.GetFirstDocument
Write # filen,"Attachment Copier to Richtext Field "
Write # filen,"Role: Copying Attachments from $File field to newly created richtext field which instantly created by this agent. 
Attachments on the same document"
Write # filen,"---------------------------------------------------------------------"
Write # filen,"---------------------------------------------------------------------"
Do While Not( doc Is Nothing)
If Not(doc.HasItem("AttachmentStatusFlag")) Then
Set coll = attachmentvw.GetAllDocumentsByKey(doc.UniversalID)
If coll.Count =>1 Then
Set attachmentdoc = coll.GetFirstDocument
Do While Not attachmentdoc Is Nothing
Set attachmentNextdoc = coll.GetNextDocument(attachmentdoc)
'******************************************
'Create RT item if not available else set the same
If Not(doc.HasItem("Extract_Attachments")) Then
Set RT = New NotesRichTextItem( doc, "Extract_Attachments" )
Else
Set RT = doc.GetFirstItem({Extract_Attachments})
End If
count=0
Forall i In attachmentdoc.Items
If i.Name="$FILE" Then
If count<1 Then
Write # filen,"UID:"&attachmentdoc.UniversalID
End If
Forall v In i.Values
Set object=attachmentdoc.GetAttachment(v)
Call Object.ExtractFile("C:\"&v)
Set object1 = RT.EmbedObject(object.Type,object.Class,"C:\"&v)
file_path="C:\"&v
Kill file_path
Write # filen,"Attachment Name:"&v
Call doc.Save(True, False)
count=count+1
End Forall
End If
End Forall
'*******************************************
Set attachmentdoc = attachmentNextdoc
Loop
'completes all the responses
doc. AttachmentStatusFlag ="Processed"
Call doc.Save(True, False)
End If
End If
Set doc=vw.GetNextDocument(doc)
Write # filen,"---------------------------------------------------------------------"
Write # filen,"---------------------------------------------------------------------"
Loop
Close filen
End Sub



Voila!!
- Contd in Part3

Comments

Popular posts from this blog

Be cautious while using '-includeusersecurity' in Export/Import Tool

Notes to SharePoint Migration - Part1