Manage Learn to apply best practices and optimize your operations.

Create Individual Text Files With Values From A Multi-Value Keyword Field.

This generic script will read in all documents in a database. In a multi-value
keyword field that you select, it will create individual text files with
another value on the document that you select.
For example:
A document has an Email field, and a multi-value keyword field of mailing lists
that they would like to belong to. (Office Equipment, Athletics)
The script will read in the email address( and place that value in
two text documents, one called "Office Equipment.txt", and the other called
Each email address that has those values will be added to the correct list. The
text documents need not be created beforehand. The keyword list can have as
many values as needed.
Sub Click(Source As Button)
Dim nameofserver As String
Dim datab As String
Dim directory As String
Dim fieldname As String
Dim referencefield As String

'Getting user input for variables
nameofserver = Inputbox$("The name of the server where the database resides:")
datab = Inputbox$("The name of the database with the .nsf extension:")
fieldname = Inputbox$("The Keyword field name:")
referencefield = Inputbox$("The field name that will be added to the text
directory = Inputbox$("The directory where the text files will be created:")

'Calling the function that will create the lists
Call createLists(nameofserver, datab, directory, fieldname, referencefield)
End Sub

Sub createLists(nameofserver$, database$, directories$, fieldname$,
Dim textList As Variant
Dim refField As Variant
Dim j As Integer, x As Integer
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection
Dim pathName As String, fileName As String

'Testing to make sure database exists.
Dim db As New NotesDatabase( nameofserver$, database$ )
If Not(db.isopen) Then
Msgbox "Could not open database."
Exit Sub
End If

'Setting collection to all docs in the database.
Set collection = db.AllDocuments

'Getting directory information.
directory$ = Dir( directories$, 16 )
If directory$ = "" Then Mkdir(directories$)

'Testing for keyword field
For j = 1 To collection.Count
Set doc = collection.GetNthDocument(j)
If doc.HasItem( fieldname$ ) Then
textList = doc.GetItemValue(fieldname$)
Msgbox "Keyword field does not exist."
Exit Sub
End If

'Testing for reference field
Forall m In textList
If doc.HasItem( referencefield$ ) Then
refField = doc.GetItemValue(referencefield$)
Msgbox "Reference field does not exist."
Exit Sub
End If

'Calling the function to write the text files.
If textList(x) <> "" Then Call WriteToFile(textList(x), refField(0))
End Forall

Msgbox("All lists have been created and/or updated.")
End Sub

Sub WriteToFile(textList$, refField$)
Dim fileNum As Integer
fileNum% = Freefile()
Dim textDoc As Variant
Dim parse_string As String
Dim result As String
Dim location As Integer
parse_string = textList$

If refField$ = "" Then Exit Sub

'Taking out illegal characters for text filenames.
result = CheckString(parse_string)
textDoc = result & ".txt"

'Writing to file
Open textDoc For Append As fileNum%
Print #fileNum%, refField$
Close fileNum%
End Sub

Function CheckString(parse) As String
'Thanks to members of for helping me 'with this function.
Const badchars = ":/"
usr_string = ""
ret_string = ""
ch = ""
usr_string = parse
For i = 1 To Len(usr_string)
ch = Mid(usr_string, i, 1)
If Instr(1, badchars, ch) Then
Print Removing Illegal Characters
ret_string = ret_string + ch
CheckString = ret_string
End If
Next i

End Function

Dig Deeper on Domino Resources - Part 3

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials'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 ...