How can I upload my files to NetSuite file cabinet using SuiteScript 2.0?
A possible option is to create a Suitelet with a Document field and save the file uploaded to that field. Here's the code for such a Suitelet:
/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
define(['N/ui/serverWidget'],
function(serverWidget) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({
title: 'Simple Form'
});
var field = form.addField({
id: 'custpage_file',
type: 'file',
label: 'Document'
});
form.addSubmitButton({
label: 'Submit Button'
});
context.response.writePage(form);
} else {
var fileObj = context.request.files.custpage_file;
fileObj.folder = 4601; //replace with own folder ID
var id = fileObj.save();
}
}
return {
onRequest: onRequest
};
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With