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 =, 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 =;

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

         log.debug(‘ fileObj ‘, fileObj);

         var content = fileObj.getContents();

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

         var id =;

         if (fileObj.size < 70) {

             content = fileObj.getContents();

             log.debug(‘content’, content);


         else {

             log.debug(‘Files is oversized’);





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 :

Facebook :

Linkedin :

Leave a Reply