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.
2
votes
3 Answers
0
votes
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
0
votes
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.