0

I have a requirement where I need to write a code in SSJS to pull data from .csv file to Lotus Notes.

I searched alot online & found code for exporting but no luck for import code.

I am new to xPages & SSJS so any reference will be highly helpfull.

Declan Lynch
  • 3,345
  • 17
  • 36
Afreen
  • 51
  • 5

2 Answers2

1

The below link is from TLCC they have some good learning resources. this one walks through how to import data from a sample CSV file. hope it helps.

http://www.tlcc.com/admin/Tips.nsf/0/513dfd72d03a9fe38525718b006fa5a8?OpenDocument&TableRow=8.1

Simon McLoughlin
  • 8,293
  • 5
  • 32
  • 56
  • Thanks for your suggestion but the link is lotusscript code for export to .csv. I was looking for the same in Server Side JavaScript. – Afreen Jun 28 '12 at 13:26
  • I know you where looking for SSJS but you could easily put this is an agent and then call the agent through SSJS, give you the best of both worlds – Simon McLoughlin Jun 28 '12 at 13:38
0

I would use java.util.Scanner. It can scan a file for you and rip it into pieces:

Scanner scanner = new Scanner(cFile);
while (scanner.hasNextLine()) {
String curLine = scanner.nextLine().trim();
    this.processRow(curLine);
}

private void processRow(String workString) {
     Scanner lineScanner = new Scanner(workString);
 lineScanner.useDelimiter(",");
     // .next goes through the elements
     lineScanner.next();

}

Let us know how it goes. A few interesting challenges you might face, depending on the structure of your CSV file (this is why you might need to do some elaborate code here)

It could be: number,string,string,"String with , inside",String,number So if you only "escape" the String with , inside you have trouble. If all Strings are in "" then you need to Strip these and you have multiple delimiters to deal with: Number,"String Number,Number "String","String" String",Number so it gets a little complicated and you might want to use the byte array and a state to go through the individual lines.

Alternatively you can give OpenCVS a shot

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • Thanks for your suggestion. I was looking for the code in SSJS. By the way the challenges you described are really helpful for writing the code from Scratch. – Afreen Jun 28 '12 at 13:29
  • Afreen, don't bother, there are too many edge cases. the OpenCVS takes care of them and you can use it in SSJS too – stwissel Jun 29 '12 at 07:32