Question

I have a large product list and need to generate a static file of it, and have that file be accessible in my website. Currently, I generate the list, and upload it to the file cabinet. I wish to automate this process. I would like to schedule a SuiteScript to run each night and generate this list and update a file in the file cabinet.

Can this be done?

thanks

Was it helpful?

Solution

You can automate this process with SuiteScript. You would use the nlapiLoadFile and nlapiSubmitFile calls to accomplish it. If you have a large product list you are likely to encounter a few other issues. You are likely to hit governance limits and will need to develop this script so that it tracks progress and reschedules itself appropriately. SuiteScript searches will only return the first 1000 records. If you have more than 1000 items to include in this file, you will likely need to use a flag on the item record to track which items remain for export. There is currently a 5MB limit on the file size when loading or creating files using SuiteScript.

OTHER TIPS

Example SuiteScript to create a file:

var data = 'Your,CSV,File,Here';
var folderId = 519; // Your File Cabinet folder ID here

// Create the file and add it to the folder
var f = nlapiCreateFile('products.csv', 'CSV', data);
f.setFolder(folderId);
var id = nlapiSubmitFile(f);

// If you want to attach the file to a record, you can do something like this:
nlapiAttachRecord('file', id, 'customrecord_x', recordId);

Yes, you could do it using scheduled Scripts and schedule them as your wish. There is no special API function to edit an existing file, you could take the details of the existing file and create a new file with the same details but changing the data field only and deleting the old file.

    var start = function(request, response)
{
    var fileId = "107524";//get the existing file id
    var file = nlapiLoadFile(fileId);
    var data = file.getValue();
    var name = file.getName();
    var folderId = file.getFolder();
    var fileType = file.getType();
    nlapiDeleteFile(fileId);//delete the older file

    data += "this is the appended data";//change the data
    var newFile = nlapiCreateFile(name, fileType, data);//create a new file with the same details
    newFile.setFolder(folderId);
    nlapiSubmitFile(newFile);//submit it
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top