Has anyone had issues reading from CSV files in Ne...
# suitescript
j
Has anyone had issues reading from CSV files in NetSuite that contain line breaks? for example a cell will have information on multiple lines but NetSuite will detect a line break in the middle of data and decide that's a new line
j
I created a few variants on this
Copy code
/**
 * @NApiVersion 2.0
 * @NScriptType suitelet
 * @NAmdConfig /SuiteScripts/configuration.json
 * @Author Jack Arens | National Food Group
 */
define(['papaparse', 'N/file'],
    function (papaparse, file) {
        var exports = {onRequest: onRequest};

        function onRequest(options) {
            var request = options.request;
            var response = options.response;

            log.debug('Request', request.files.upfile);

            var csv = request.files.upfile.getContents();

            //This breaks when '\n' is in a cell
            log.debug('Read CSV', readCSV(csv));

            //This breaks when '\n' is in a cell
            var iterator = request.files.upfile.lines.iterator();
            iterator.each(function (line) {
                log.debug('Line', line);
                return true;
            });

            //Doesn't break when '\n' is in a cell
            log.debug('Papa Parse', papaparse.parse(csv).data);

            response.writePage({
                output: 'File Received'
            });
        }

        function readCSV(csv) {
            return csv.split('\n');
        }

        return exports;
    });
Seems like papaparse can handle the issue. https://github.com/mholt/PapaParse
j
Much appreciated, I'll look in to this!