简体   繁体   English

netsuite suitescript 2.0导出(csv)

[英]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). 当使用“导出”(CSV)从“搜索”页面导出时,是否可以以相同的方式使用Suitescript 2.0导出搜索结果。 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. Netsuite Answers表示,这可以通过构建CSV文件来完成,我想知道是否可以按原样运行Export(CSV)。 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. 我需要执行此操作,因为每周需要运行许多搜索,这些搜索必须下载到Excel中,并且我希望使用脚本来执行此操作,而不是手动选择每个搜索。

使用N/task.SearchTask API。

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 . Netsuite提供的内置解决方案是安排已保存的搜索以发送电子邮件,并以CSV格式作为附件发送已保存的搜索结果。

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 或者,您也可以找到第三方库,以将JSON转换为CSV并将保存的搜索结果转换为想要以CSV格式存储的JSON格式

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 参考: SuiteScript 2.0 API页面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. 然后,我检查文件是否足够新(脚本没有失败),然后下载并处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM