October 22, 2024
Chicago 12, Melborne City, USA
pdf

How to zip file in a Netsuite suitescript?


I have developed a suitelet script to generate pdf and xml file. Now I want to zip both the files into a single zip file and store it to the Netsuite file cabinet. Please help!

Below is my script snapshot
/**
*@NApiVersion 2.1
*@NScriptType Suitelet
*/
define([‘N/file’, ‘N/redirect’, ‘N/record’, ‘N/runtime’, ‘N/search’, ‘SuiteScripts/invoice_module_refactored’, ‘N/compress’], function (file, redirect, record, runtime, search, pdfModule, compress) {

function onRequest(context) {
        //Get record ID and record type from request parameters
        var recordId = context.request.parameters.recordId;
        log.debug("recordId", recordId);
        var recordType="invoice";

        var pdfFile = pdfModule.getPDF(recordType, recordId)
        log.debug("pdfFile", pdfFile);
        pdfFile.folder = 12823;
        var pdfFileId = pdfFile.save();
        log.debug("pdfFileId", pdfFileId);

            // Create and save the XML file in the File Cabinet
            var fileObj = file.create({
                name: 'E-Invoice_' + recordId + '.xml',
                fileType: file.Type.PLAINTEXT,
                contents: xmlContent
            });

            //Specify the folder ID where the file should be saved
            fileObj.folder = 12823; // Change to your actual File Cabinet folder ID
            var xmlfileId = fileObj.save();
            log.debug("xmlfileId", xmlfileId);
       
}

    return {
    onRequest: onRequest
};

});



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video