Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a file from local to NetSuite file cabinet using SuiteScript 2.0

How can I upload my files to NetSuite file cabinet using SuiteScript 2.0?

like image 334
amit biswas Avatar asked Dec 14 '22 17:12

amit biswas


1 Answers

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
    };
});
like image 147
Maria Berinde-Tampanariu Avatar answered Dec 17 '22 23:12

Maria Berinde-Tampanariu