Hi I have a code that exports to CSV file. But I e...
# suitescript
t
Hi I have a code that exports to CSV file. But I encounter NAN whenever the value I exported have a : (colon). Any advise? I am using a suitelet to export the data into CSV
a
Is the CSV file being exported from search results? are you manipulating the data to add/update rows? • If you are just exporting a search consider this:
task.SearchTask
this is native NetSuite export task (basically the same as clicking export to CSV in the UI), so you don't need to worry about data parsing etc. • If you are manually updating/building the data via code, then consider https://www.papaparse.com/
t
I am doing it manually. Thanks @alien4u
a
Then your best bet is papaparse it will handle all the parsing for you very accurately...
Copy code
var s_csvFile = Papa.unparse(reportArray, {
    delimiter: "\t",
    header: true
});
t
my client says don't display the : anymore. Just replace it with - or _. I am trying to do it using regex but when it display in CSV its shows NaN again
Copy code
var str = customerNo[i];
var customerNumber = str.replace(/:/g, '_');
nlapiLogExecution('ERROR', '-- customerNumber --', JSON.stringify(customerNo) + ' replace=' + customerNumber);

csvDetails += "\n" + salesRep[i] + "," + prodManager[i] + "," + dropShip[i] + "," + location[i] + "," + customerName + "," +
    + customerNumber + "," + item[i] + "," + contractExp[i] + "," + safetyStockSugg[i] + "," + supplyChain[i] + "," +
    + safetyStockAgreement[i] + "," + prodGroup[i] + "," + warehouse[i] + ",";
s
please embrace template strings
or better yet, take @alien4u advice and use papaparse
t
Not sure if template string allowed in 1.0 though šŸ¤”
Yeah probably if there is no other way to catch it I might use papaparse in 1.0. Have you guys try using it in 1.0?
s
template strings won't work in SS1.0 unless you are using a transpiler like TypeScript
šŸ‘ 1
I recommend modernizing the script to SS2.x
but all said, papaparse should do a better job
t
Even I recommended it, but they want 1.0 what yeah will try to check on this. I haven't tried using libraries outside NS before šŸ™‚
Will update you guys šŸ‘
s
you have a typo before customerNumber, there are 2 + signs which is causing the problem
šŸ‘ 1
t
Untitled
correct I revisited the code and I notice that the "+" cause this šŸ™‚ thanks @Selcuk Dogru