I am attempting to create a historical csv backup (appended rather than overwritten) to our file cabinet using a saved searches results (on a once a week schedule).
I know its possible to write a saved searches results to a CSV (using task), but I’m not sure how I can append instead (maybe using file.appendline?). Here is what I’ve come up with which results in the appended data being “task.SearchTask” instead of the saved search results:
/**
* @NApiVersion 2.1
* @NScriptType ScheduledScript
*/
define(['N/file', 'N/task'],
/**
* @param{file} file
* @param{task} task
*/
(file, task) => {
/**
* Defines the Scheduled script trigger point.
* @param {Object} scriptContext
* @param {string} scriptContext.type - Script execution context. Use values from the scriptContext.InvocationType enum.
* @since 2015.2
*/
//[file ID, Saved Search ID]
const keys = [
[72567, 1701]
]
const execute = (scriptContext) => {
for(var i = 0; i < keys.length; i++) {
var searchTask = task.create({
taskType: task.TaskType.SEARCH,
savedsearchId: keys[i][1]
});
var csvFile = file.load({
id: keys[i][0]
});
//This probably doesn't work...
csvFile.appendLine({
value: searchTask
});
csvFile.save();
}
}
return {execute}
});
Any assistance would be appreciated!