Customizing CSV Export with LotusScript

Data export is a fundamental task in any database environment, and HCL Notes is no exception. While Notes offers a built-in feature to export data to a CSV file ( Refer: How can I export view data in CSV files? ), this process can come with a few challenges, especially for complex or multi-layered data.

When you use the standard export feature of Notes, you might run into issues such as:

  • Handling Multi-Value Fields: Fields with multiple values can often be incorrectly formatted or lose data during the export.
  • Categorized Views: The hierarchical structure of categorized views may not translate correctly, leading to misplaced or missing data.
  • Blank Columns: Empty columns in your view are typically represented as “”, which can be a nuisance to deal with later.
  • Hidden Data: Information within collapsed sections of a document won’t be exported unless you manually expand them first.
  • Configuration Errors: You might see an “Import/Export not configured” error if your notes.ini file is missing specific entries ( Refer: Error "Import/Export not configured" appearing while trying to export from a view - Customer Support ).

For simple data sets, the native export feature works fine. But for more complex scenarios, a customized approach is often the best solution. When you need more control over how your data is exported, using a LotusScript agent is the way to go. This allows you to handle special cases, such as multi-value fields or specific formatting, with precision.

I am sharing a sample LotusScript code that demonstrates how to export your Domino data to a CSV file. For this example, we’ll export a few fields — FirstName, LastName, and Age — but you can easily add as many fields as you need.

This script will write a file named “Export.csv” to your C: drive. Just make sure your account has write access to the specified path, or change the destination in this line of the code:
exportcsv = "C:\Export.csv" 'mention here the drive and path to export CSV file

Replace “ViewName” with the name of the specific view you want to export at following line of the code. This view should contain the documents with the data you need to export:
Set vw = db.Getview("ViewName") ‘mention here the view name that has documents to be exported

Mention the column headers at following line of the code. Make sure these column headers match the fields you are exporting:
Print #file,"FirstName,LastName,Age" ‘mention here column headers

The data line defines the fields that will be exported from each document. For each field, use the format doc.FieldName(0). You can add as many fields as you need, separated by & “,” & at following line of the code. Make sure the fields match the column headers.
data = doc.FirstName(0) & "," & doc.LastName(0) & "," & doc.Age(0) ‘mention here fields to be exported

Once you add this script to your agent, set its target to “None” in the agent properties. When the agent runs successfully, all your data will be exported cleanly and correctly to your chosen location.

Sample Script

Sub Initialize
Dim sess As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim exportcsv As Variant
Dim file As Integer
Dim data As String
Dim vw As NotesView

file = FreeFile
exportcsv = "C:\Export.csv"     'mention here the drive and path to export CSV file
Open exportcsv For Output As file
data =""

Set db = sess.Currentdatabase
Set vw = db.Getview("ViewName")	‘mention here the view name that has documents to be exported
Set doc = vw.Getfirstdocument()

Print #file,"FirstName,LastName,Age"     ‘mention here column headers

While Not doc Is Nothing
data = doc.FirstName(0) & "," & doc.LastName(0) & "," & doc.Age(0)      'mention here fields to be exported
Print #file,data
Set doc = vw.Getnextdocument(doc)
Wend

Close file
	
End Sub

Disclaimer

This sample script is provided as a starting point. We recommend that you adapt it to your specific production needs and work with your development and quality assurance teams to ensure a smooth implementation. HCL Support cannot provide further customization, as writing custom code falls outside the support scope. All customizations should be done at your own discretion.