Print SearchResult in CSV in NetSuite SuiteScript 2.0

Print SearchResult in CSV in NetSuite SuiteScript 2.0

In this tutorial of netsuite solution provider you will learn ,The file Module helps us to do lots of thing in the NetSuite

Load the file module when you want to work with files within NetSuite. We can use this module to upload files to the NetSuite File Cabinet. You can also use this module to send files as attachments without uploading them to the File Cabinet.

file.create(options) : Method used to create a new file in the NetSuite File Cabinet.

Click on the link if you are looking for netsuite solution provider.

file.delete(options) : Method used to delete an existing file from the NetSuite File Cabinet.

File.load(options) : Loads an existing file from the NetSuite File Cabinet. The file size limit for this method is 2GB.

fileObj.getContents() : Method used to return the content of the file.

fileObj.size() : It Will return the size of the file.

In the below script which can be used in netsuite implementation and netsuite customization we are running a search and printing the search result in the file and appending the line after that and also using file.size() to validate the file size.

/**

* @NApiVersion 2.x

*/

require([‘N/file’,’N/search’], function (file,search) {

    function createAndSaveFile() {

    // load search for which you want to generate a file 

        var searchObj = search.load({

            id: ‘customsearch_test_demo_ss’

            //       type: string

        })

        var i = 0;

        var searchObjResult = searchObj.run().getRange(0, 99);

        var fileObj = file.create({

            name: ‘Demo_cust_file6.csv’,

            fileType: file.Type.CSV,

            contents: searchObjResult[0].getvalue({name:’entity’})

        });

       fileObj.folder = 151607;

       var id = fileObj.save();

        //log.debug(‘id is ‘+ id);

         log.debug(‘ fileObj ‘, fileObj);

         var content = fileObj.getContents();

         fileObj.appendLine({ value: ‘Test value to append’ });

         var id = fileObj.save();

         if (fileObj.size < 70) {

             content = fileObj.getContents();

             log.debug(‘content’, content);

         }

         else {

             log.debug(‘Files is oversized’);

         }

    }

    createAndSaveFile();

});

Feel free to reach out Netsuite Solution provider  TheSmilingCoders for proper netsuite implementationnetsuite consultation , netsuite customizationnetsuite Supportnetsuite Training NetSuite Celigo Integration , Celigo ConsultantCeligo Integration Consultant.

contact us : [email protected]

Facebook : https://www.facebook.com/Smiling-Coders-Netsuite-Training-Implementation-and-Support-1591053827660082/

Linkedin : https://www.linkedin.com/company/netsuite-academy/


Log out of this account

Leave a Reply