BobJakobs
BobJakobs

Reputation: 21

netsuite suitescript 2.0 export(csv)

Is there a way to export search results using suitescript 2.0 in the same way when exporting from the Search page using Export(CSV). Netsuite Answers says that this can be done by building a CSV file, I would like to know if I can run the Export(CSV) as is. I need to do this because I have many searches that I need to run weekly which have to be downloaded to Excel and I would like to have a script do this instead of manually selecting each one.

Upvotes: 2

Views: 6665

Answers (4)

Maira S
Maira S

Reputation: 59

yes we can export search results using suitescript 2.0. Simplay you can use task.SearchTask API which is present in N/task module.

Upvotes: 0

Brian
Brian

Reputation: 7299

Really quick code of a scheduled script that puts the results of a saved search into an exiting file.

Ref: SuiteScript 2.0 API page 792

/**
 *@NApiVersion 2.x
 *@NScriptType ScheduledScript
 */
define(['N/task','N/log'],

    function(task)
    {
      function execute(context)
      {
        //create search task
        var myTask = task.create({
            taskType: task.TaskType.SEARCH
            });
        myTask.savedSearchId = 4222;
        myTask.fileId = 14581313; 
        var myTaskId = myTask.submit();
        log.audit({title:"Task submitted.",
                   details:"Put results of savedSearchId:4222 in csv file InternalID:14581313"});
      }
      return {execute: execute
      }
   });

I then check if the file is new enough (the script didn't fail) and download and process it.

Upvotes: 0

erictgrubaugh
erictgrubaugh

Reputation: 8902

Use the N/task.SearchTask API.

Upvotes: 3

Manu AVS
Manu AVS

Reputation: 575

The inbuilt solution provided by Netsuite is to schedule the saved search to send email with the saved search results to be send as attachment in CSV format .

Alternatively, you can also find third party library to convert JSON to CSV and convert the saved search result to JSON format you want to be in CSV

Upvotes: 1

Related Questions