We have to create some custom records from a csv, ...
# suitescript
r
We have to create some custom records from a csv, CSV import will not work properly, as the raw file needs to be cleaned out first. Have written a script to clean the CSV, most of the scenario its working fine. One challenge I am facing is, one of the csv file has comma in columns itself. which vary form row to row so I am not able to put some logic into it as well. So once I do
Copy code
obj_rawCSV = file.load(i_rawCsvFileId);
obj_csvContent = obj_rawCSV.getContents();
obj_csvContent = obj_csvContent.split(/\n|\n\r/);
a_RowData = obj_csvContent[index].split(",");
Once I split the columns for each row its giving different number of columns for each row. Is there anyway I can iterate through the columns of CSV, without splitting it with comma?
d
yes, I dealt with this issue, give me a minute to dig out the code
I had issues with the N/file module's
file.reader
splitting incorrectly
b
d
Actually I had issues with the
csvFile.lines.iterator
incorrectly splitting values that contained newline characters. See module snippet
@battk, yeah, I'm now using papaparse as part of a csv file validator Do you know of a schema for CSV validation (similar to using XSD for XML)?
r
thanks @David B will check this.
d
check out papaparse, that's the most robust way to go
e
Yep +1 on papaparse here
No need to re-write the wheel, as it were
r
papaparse working fine, thank you everyone.