Create CSV file from Saved Search using SuiteScript (N/task module)

This is more of an informational post than a question. I spent a lot of time using the N/file module to generate CSV files from saved searches in SuiteScript, and it was a headache trying to make sure I escaped all the characters correctly so that the final CSV file would look like the CSV file that would be generated from clicking the button on the results page of a Saved Search.

After much time spent on this, it was brought to my attention that the N/task module creates CSV files from Saved Searches in just a couple lines of code. Not only is it much simpler, but it is also much faster than manually iterating through all the results of a Saved Search in SuiteScript and adding them to the CSV file one by one. The article on this topic and the code from that article are below.

* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
* @param {record} record
* @param {search} search

function(task) {
var FILE_ID = 20; 
var SEARCH_ID = 19;
function execute(scriptContext) {
var searchTask = task.create({
taskType: task.TaskType.SEARCH
searchTask.savedSearchId = SEARCH_ID;
searchTask.fileId = FILE_ID;
var searchTaskId = searchTask.submit();
return {
execute: execute

Rookie Asked on April 13, 2021 in SuiteScript.

I think your post just saved me a ton of time and effort! Thanks!

on July 21, 2021.
Add Comment
1 Answer(s)

Thanks for linking our article on this! Saved so much time for our team as well hence I thought it’s worth sharing to everyone. 🙂

Beginner Answered on February 20, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor