Q
Problem solve Get help with specific problems with your technologies, process and projects.

Personal doc in public address book from data in .CSV file

I have a small application where I have to create a personal document in the public address book from data in a .CSV file. Can you please help me?
This is perfectly possible, and you can do it with LotusScript using the Line Input# statement to read a line at a time, and then parse the line in your code. How easy this is depends in large part on how the .CSV file is formatted. It's easier to work with a file that just has plain values separated with commas:

Albert,Weeks,"Albert Weeks" <aweeks@somewhat.org>,653-909-2020,...

You can use the Split function in LotusScript to change it into an array with the value for each field being at the same array index on each row. E.g.:

Line Input #fn, strLine
Do Until strLine = ""
arrFields = 
Split(strLine, ",")
Dim docNew As
 New NotesDocument(db)
docNew.Form = "Person"
docNew.FirstName = 
arrFields[0]
docNew.LastName = 
arrFields[1]
...
docNew.Save
Line Input #fn, strLine
Loop 

And so on (I've left out some details of variable declarations, getting the db object, etc.). Of course, sometimes you encounter .CSV files where every string is in quotes and if there are quotes in the data, they are escaped. E.g.:

"Albert","Weeks","""Weeks, Albert"" <aweeks@somewhat.org>","653-909-2020",...

This can still be done but it's harder to code because you can't just Split on the commas -- some of the commas are part of the data. You have to parse the string one character at a time and keep track of whether you are inside of quotes, to know when you have reached the end of a field.

You can also import a .CSV file into a Notes view using the File -> Import function from the menu. However, this requires that the .CSV file be in a format that matches the view, and this may not be convenient to arrange.

Yet another option, if you have a copy of LEI (Lotus Enterprise Integrator), is to use a "Direct Transfer" activity to move data between a "Text connection" (your file) and a "Notes connection" (your Notes database). This doesn't require any programming, but it does require that you supply a "ZID" description of the contents of the .CSV file. The ZID format is described in the Domino Designer help, and is simple if the file doesn't contain fancy formatting, but probably not possible if the data contains escaped quotes and commas, as in the second example above.

If you don't have LEI, you can still use the Text connector to pull your data from the file and the Notes connector to insert it into Notes, but then you're back to programming, and it's probably just as easy to parse the data yourself as described above.

Do you have comments on this Ask the Expert question and response? Let us know.

This was last published in January 2005

Dig Deeper on LotusScript

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

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

SearchExchange

SearchContentManagement

Close