Manage Learn to apply best practices and optimize your operations.

How Do You Do A Data Import/Merge Using Lotuscript ?

This function can be placed in an action button in a database.
Sub Initialize

On Error Goto _Error

Dim bFileOpen As Integer
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase

Dim view As NotesView
Dim doc As NotesDocument
Set view = db.GetView( "(CleanAddress)" )
Set doc = view.GetFirstDocument

' The Fields we are going to import
Dim Field1 As String
Dim Field2 As String

' The unique field for each record
Dim UniqueID As String

' Name of file to get from user
Dim FileName As String

If Not (doc Is Nothing) Then
FileName = Inputbox$("Enter your import file name: ", "Data Import", "C:\")
If (FileName = "") Then
Messagebox ("Import has been cancelled")
Exit Sub
End If
Else
' There is nothing to merge into
Messagebox ("Nothing to merge into! Are you sure you have already imported
this file?")
Exit Sub
End If

' Open the file
Dim fileNum As Integer
fileNum = Freefile()
Open FileName For Input As fileNum
bFileOpen = 1

Dim item As NotesItem
' Until we eof
Do Until Eof (fileNum)
Input #fileNum, UniqueID, Field1, Field2
If (UniqueID > "") Then
Set doc = view.GetDocumentByKey(URN)
If Not (doc Is Nothing) Then
doc.Field1 = Field1
doc.Field2 = Field2
Call doc.Save(True, False)
Else
Messagebox("File contains a record that is not in the database " +
UniqueID)
End If
Else
Messagebox("File contains an record without a unique id")
End If
Loop

' Close file
Close fileNum
bFileOpen = 0

Messagebox("File imported successfully")
Exit Sub

_Error:
If (bFileOpen = 1) Then
Close fileNum
End If
Messagebox("Error importing data: " + Error$)

End Sub

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close