skip to Main Content

Issue:

I’m facing issue while making a custom record of the online form which I’m getting from Shopify in NetSuite and this happens because I’m unable to upload the attachment or file into the file cabinet.

Tried:

I tried to convert the file or attachment into base64 and also through blob too but unable to get the desired result because Netsuite has limitations that it can’t handle more than 1000 characters and this also not a good workaround as the user has the privilege to update the image.

In Code:

Created an online HTML form and map their field with their related field and create a custom record for every record and I’m successfully able to map all the field except attachment(.png, .pdf, .png, etc)

Is there any way to get the result i.e successfully create the custom record through online HTML form or any other workaround to get the result?

3

Answers


  1. Chosen as BEST ANSWER

    For, Now whatever I checked or searched regarding upload image, maybe we are not able to upload an image into their respective field until and unless we save the particular file into the file cabinet.

    So, I opt for some other method that is by going through suitelet and then POST the same form after storing the file in the file cabinet into the respective field.

    Here, is my workaround code:

    var dataBody = JSON.parse(request.getBody());
    nlapiLogExecution("debug", "POST BLOCK", 'dataBody = ' + JSON.stringify(dataBody));
    var file_folder = '2442342';
    var contents = dataBody.imgdata;
    var fileType = dataBody.fileType;
    var date = new Date();
    var newDate = date.getMilliseconds() + date.getTime();
    var type = '';
    var ext = '';
    if ((fileType == 'plain') || (fileType == 'PLAIN')) {
        type = 'PLAINTEXT';
        ext = 'txt';
    }
    if ((fileType == 'pdf') || (fileType == 'PDF')) {
        type = 'PDF';
        ext = 'pdf';
    }
    if ((fileType == 'png') || (fileType == 'PNG')) {
        type = 'PNGIMAGE';
        ext = 'png';
    }
    if ((fileType == 'jpeg') || (fileType == 'JPEG')) {
        type = 'JPGIMAGE';
        ext = 'jpeg';
    }
    if ((fileType == 'jpg') || (fileType == 'JPG')) {
        type = 'JPGIMAGE';
        ext = 'jpg';
    }
    
    var name = newDate + '.' + ext;
    nlapiLogExecution("debug", "POST BLOCK", 'File Type: ' + type);
    try {
        if (type) {
            var uploadFile = nlapiCreateFile(name, type, contents);
            uploadFile.setFolder(file_folder);
            var FileId = nlapiSubmitFile(uploadFile);
            nlapiLogExecution("debug", "POST BLOCK", 'Image File ID: ' + FileId);
        }
        if (FileId) {
            warr.setFieldValue('custrecord_file_id', FileId);
        }
    } catch (err) {
        nlapiLogExecution("debug", "POST BLOCK", 'Error: ' + err);
    }
    

    Hope it helps others. And one more thing you need to decrypt the data as you saving in the file cabinet but if you change the file type to jpg image in all then you may do not need to need to convert it. Thanks


  2. As far as I can find, the file cabinet is not available to online forms.

    As a workaround, you could have Shopify “receive” the file, then code it to send the file to NetSuite via a custom email capture plugin.

    Put the right data on the subject line so your capture script knows where to put the file.

    Login or Signup to reply.
  3. /**
     * @NApiVersion 2.x
     * @NScriptType Suitelet
     * @NModuleScope SameAccount
     */
    define(['N/ui/serverWidget', 'N/record', 'N/runtime', 'N/file', 'N/log'],
    
    function(serverWidget, record, runtime, file, log) {
    
        /**
         * Definition of the Suitelet script trigger point.
         *
         * @param {Object} context
         * @param {ServerRequest} context.request - Encapsulation of the incoming request
         * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
         * @Since 2015.2
         */
        function onRequest(context) {
            if(context.request.method === 'GET'){
                var formObj = serverWidget.createForm({
                    title: 'Attach Multiple Files'
                });
    
                var userId = runtime.getCurrentUser().id;
    
                //User Name
                var user = formObj.addField({
                    id: 'custpage_suitelet_user',
                    type: serverWidget.FieldType.SELECT,
                    source: 'employee',
                    value: userId,
                    label: 'USER'
                });
                user.defaultValue = userId;
    
                //File fields
                formObj.addField({
                    id: 'custpage_suitelet_file1',
                    type: serverWidget.FieldType.FILE,
                    label: 'File 1'
                });
                formObj.addField({
                    id: 'custpage_suitelet_file2',
                    type: serverWidget.FieldType.FILE,
                    label: 'File 2'
                });
                formObj.addField({
                    id: 'custpage_suitelet_file3',
                    type: serverWidget.FieldType.FILE,
                    label: 'File 3'
                });
    
                formObj.addSubmitButton({label: 'Submit'});
                formObj.addResetButton({label: 'Reset'});
    
                context.response.writePage(formObj);
            }
            else{
                var userId = runtime.getCurrentUser().id;
    
                var file1 = context.request.files['custpage_suitelet_file1'];
                var file2 = context.request.files['custpage_suitelet_file2'];
                var file3 = context.request.files['custpage_suitelet_file3'];
    
                file1.folder = 624; //folder internal ID
                file2.folder = 624; //folder internal ID
                file3.folder = 624; //folder internal ID
    
                var id1 = file1.save();
                var id2 = file2.save();
                var id3 = file3.save();
    
                record.attach({
                    record: {
                        type: 'file',
                        id: id1
                    },
                    to: {
                        type: 'employee',
                        id: userId
                        }
                });
                record.attach({
                    record: {
                        type: 'file',
                        id: id2
                    },
                    to: {
                        type: 'employee',
                        id: userId
                        }
                });
                record.attach({
                    record: {
                        type: 'file',
                        id: id3
                    },
                    to: {
                        type: 'employee',
                        id: userId
                        }
                });
    
                var formObj = serverWidget.createForm({
                    title: 'File/s attached!'
                });
                context.response.writePage(formObj);
            }
        }
    
        return {
            onRequest: onRequest
        };
    
    });
    

    I get the script from SuiteAnswers. It’s for 2nd version of NS script. The suitelet can be used via an iframe. You could directly attach the file to a the record and/or populate the custrecord_file_id. This it not the best practice if you have limited storage space.

    In my case, for return/repair form where the customer should upload a video or an image of the damaged product. I used the “google script” to upload the file into google drive and and I post only the URL to Netsuite via Suitelet.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search