Export Saved Search to CSV with CRLF

I have a need to export the results of a saved search to a CSV file.  My code works well except the consuming system expects CRLF.  The output from the script appears to only contain LF. The saved search has 57 columns and I was hoping to use N/task without having to build an array of every single column.

Any help would be greatly appreciated.

 

/**

*@NApiVersion 2.x

*@NScriptType ScheduledScript

*/

define(['N/task','N/record','N/file','N/search','N/log'],

/*

Add following modules to define as required:

N/runtime - used to get parameters from scripts

N/search - used to load and execute saved searches

N/file - used for file operations

N/record - used to operate on records returned in search results and create records

N/format - used for formatting operations

*/

function(task, record, file, search)

{

function execute(context)

{

// Define Variables

var today = new Date();

var fileNamePrefix = 'NETSUITE_GLTNX_'

var csvFile = ''
// Get Parameters
// Create File

var fileName = fileNamePrefix + dateSuffix(today) + '.csv';
var myFileToUpload = file.create({

name: fileName,

fileType: file.Type.CSV,

contents: csvFile,

encoding: file.Encoding.WINDOWS_1252,

folder: 509

});

var fileID = myFileToUpload.save();
//create search task

try {

var myTask = task.create({

taskType: task.TaskType.SEARCH

});

myTask.savedSearchId = 266; // 266 is detail. 309 is checksum

myTask.fileId = fileID;

var myTaskId = myTask.submit();

log.audit({title:"Task submitted.",

details:"Put results of savedSearchId:266 in fileID"});

}catch (e) {

log.debug('catch ' + e.toString());

}
//Helper functions

function dateSuffix(date) {

//BEGIN: get current date elements

var date = new Date();

var tdate = date.getDate();

var month = date.getMonth() + 1; // jan = 0

var year = date.getFullYear();

if (tdate < 10) {

tdate = '0' + tdate;

}

if (month < 10) {

month = '0' + month;

}

//END: get current date elements
//BEGIN: get current period end elements.
var today = new Date();

var lastDayOfMonth = new Date(today.getFullYear(), today.getMonth()+1, 0);

var perday = lastDayOfMonth.getDate();

var permonth = today.getMonth() + 1; // jan = 0

var peryear = today.getFullYear();

if (lastDayOfMonth < 10) {

lastDayOfMonth = '0' + lastDayOfMonth;

}

if (permonth < 10) {

permonth = '0' + permonth;

}

//END: get current period end elements
 
//return currentDateTime = month + '_' + tdate + '_' + year + '_' + hours + minutes + seconds;

return currentDateTime = year + month + tdate + '_' + peryear + permonth + perday ;
}
}

return {execute: execute

}

});
Rookie Asked on August 5, 2021 in SuiteScript.
Add Comment
0 Answer(s)

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   Limebox   Become a Sponsor