Domino Code Fragment

Code Name*
Using LotusScript for Unattended File Import in a Notes View
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.149.233.72
Description*
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Problem:
When you import data into documents via a view import in Notes R4, the import has to be
confirmed with the shown dialog box. Even with an agent that is defined as follows:

@Command([FileImport];"Structured Text";"c:\\developm\\ltsscrpt\\data.txt")

you see the Import dialog box.



How can you use an unattended file import in a view?

Solution:
IMPORTANT NOTE: The following is a sample script, provided only to illustrate one way to
approach this issue. In order for this example to perform as intended, the files must be laid out
exactly as indicated below. Notes Support will not be able to customize this script for a customer's
own configuration. While this has worked for many customers it is offered as a suggestion only, and
is not something that Lotus supports further.

The LotusScript program below reads a structured text file using a COL file structure, and creates
documents in the view using its data, without getting dialog boxes. Place the code into an agent that
runs once manually from the action menu or runs on schedule on all documents in the database (runs
only once).

The COL file for structured data should look like the following (you can use any delimiter type), and
is the same as the existing COL files.

DATA.COL:

Name:UNTIL ','
Age:UNTIL ','
Country:UNTIL ''

The structured text file with as row the Notes document data is then filled up as follows.

DATA.TXT:

Brown, 12, France
Hilhorst, 28, France

Finally, the script that is placed in the Initialize method of the agent and the declarations in its own
section:

Declarations:

Type ColStruc
FieldName As String
FieldDelimiter As String
End Type

Sub Initialize

Dim Fields() As ColStruc
Dim FieldCntr As Integer
Dim Counter As Integer
Dim txt As String
Dim ColFileName As String
Dim DataFileName As String
Dim FormName As String
Dim FieldContents As String
Dim pos As Integer

Dim session As New NotesSession
Dim db As NotesDataBase
Dim doc As NotesDocument

' Set the names. These
ColFileName="c:\developm\ltsscrpt\data.col"
DataFileName="c:\developm\ltsscrpt\data.txt"
FormName="Test form"

' Determine the number of fields described.
Counter = 0
Open ColFileName For Input As 1
Do While Not Eof(1)
Line Input #1,txt$
Counter = Counter +1

' Correct if the line is empty (less than 3 characters), so ignore then the line
If Len(txt$)<3 Then
Counter = Counter - 1
End If
Loop


' Now read the field names with their delimiters
Redim Fields(1 To Counter)
' Move to first record again
Seek 1, 1
FieldCntr=1
Do While Not Eof(1)
Line Input #1, txt$
If Len(txt$)>3 Then
pos=Instr(txt$,":")
Fields(FieldCntr).FieldName=Left$(txt$,pos-1)
pos=Instr(txt$,"'")
Fields(FieldCntr).FieldDelimiter=Mid$(txt$,pos+1,Len(txt$)-pos-1)
FieldCntr = FieldCntr + 1
End If
Loop
Close 1

Set db = session.CurrentDatabase

' Now read the data file
Open DataFileName For Input As 1
Do While Not Eof(1)

' For each row, create a document
Set doc = New NotesDocument(db)
Line Input #1, txt$
For FieldCntr=1 To Counter

' Determine the content of the field
pos=Instr(txt$,Fields(FieldCntr).FieldDelimiter)
If Fields(FieldCntr).FieldDelimiter="" Then

FieldContents=txt$

Else

If txt$<>"" Then
FieldContents=Left$(txt$,pos-1)
Else
FieldContents=""
End If
End If

If Len(txt$)-pos-1>0 Then
txt$=Right$(txt$,Len(txt$)-pos-1)
Else
txt$=""
End If
' and when determined, store it into the document
doc.AppendItemValue Fields(FieldCntr).FieldName, FieldContents
Next

' If you want to can add this field too.
doc.From=session.UserName

' Of course we will give it a form name
doc.Form=FormName
doc.Save False, False

Loop
Close 1

End Sub