SuiteScript Example – Read File Line by Line – Stoic Software

PHOTO EMBED

Sun Mar 27 2022 12:15:50 GMT+0000 (Coordinated Universal Time)

Saved by @mdfaizi #javascript

define(["N/file"], function (f) {

    /**
     * Custom module for executing N/file cookbook examples
     *
     * @NApiVersion 2.0
     * @NModuleScope SameAccount
     */
    var exports = {};

    function readFile(response) {
        var weatherFile = f.load({id: "SuiteScripts/weather.csv"});

        var weatherData = [];
        weatherFile.lines.iterator().each(function (line) {
            var w = line.value.split(",");
            weatherData.push({date: w[0], low: w[1], high: w[2]});
            return true;
        });

        response.write({output: JSON.stringify(weatherData)});
    }

    exports.readFile = readFile;
    return exports;
});
content_copyCOPY

https://stoic.software/effective-suitescript/suitescript-example-read-file-line-by-line/