Hello everyone, How to read data using Suitelet fr...
# suitescript
n
Hello everyone, How to read data using Suitelet from an Excel file present in File cabinate and manipulate data by applying some filters using Suitelet script??
b
try very hard to not accept excel as an input
😂 2
👍 1
otherwise you will have to learn https://sheetjs.com/
👍 2
m
Would be much better if the excel was converted to a CSV format before adding to the file cabinet. This can easily be done with your spreadsheet program. I have successfully loaded Papa Parse as a module and used within scripts to parse CSV files. Then when you have in the file cabinet you would use the 'N/file' to read the file contents and pass to the parser.
n
Thanks @battk & @Marvin I’ll go with Papa Parse!! it looks good
@Marvin can I directly load this Papa Parse library in suitelet script and use it?? to show csv file data in suitelet and can manupulate that data??
m
This is how I load it in.
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ScheduledScript
 */
// eslint-disable-next-line no-undef
define(['../cafb-scripts/modules/papaparse.min'],
    /**
     * @param Papa
     */
    (Papa) => {
As far as loading it into a suitelet you can do that through a JSON object for manipulation. Then convert back to CSV using Papa Parse.
There is supposed to be a way to load third-party scripts using a JSON config and the following.
Copy code
@NAmdConfig  ./JsLibraryConfig.json
but I have never got it to work.
n
okay
I was thinking of using below code instead!!
Copy code
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;
});