netsuite suitescript 2.0 export(csv)

烈酒焚心 提交于 2021-01-28 02:50:27

问题


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.


回答1:


Use the N/task.SearchTask API.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/51232560/netsuite-suitescript-2-0-exportcsv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!