NDAZ-51 CS R&L BOL PDF

DESCRIPTION
Get the tracking number for the
View the corresponding BOL pdf for the BOL in R&L carrier

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
/*******************************************************************************
 * NDAZ-51 PDF FOR r&l
 * **************************************************************************
 * 
 * Date: 29-07-2019
 * 
 * Author: Jobin & Jismi IT Services LLP
 * 
 *****************************************************************************
 **/
define(['N/search', 'N/https', 'N/record', 'N/currentRecord', 'N/url', 'N/email', 'N/xml'],
    function(search, https, record, currentRecord, url, email, xml) {
        var main = {
            pageInit: function(scriptContext) {},
            printbol: function() {
                var itemFUlfillment = currentRecord.get().id;
                var itemFUlfillmentRec = currentRecord.get();
                var trackingNumber = itemFUlfillmentRec.getValue('custbody_jj_ndaz_44_rl_bolid'); //'7708160'
                var APIKey = 'MtN4OGEmA0ZzZiOTEtNjQ0OC00NGExLWFhN2YzliMwNDNTcTC';
                var Xmlfile = '<?xml version="1.0" encoding="utf-8"?>' +
                    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                    '<soap:Body>' +
                    '<GetBillOfLadingPdf xmlns="http://www.rlcarriers.com/">' +
                    '<APIKey>' + APIKey.replace(/&/g, '&') + '</APIKey>' +
                    '<billOfLadingId>' + trackingNumber.replace(/&/g, '&') + '</billOfLadingId>' +
                    '</GetBillOfLadingPdf>' +
                    '</soap:Body>' +
                    '</soap:Envelope>';
                console.log('Xmlfile', Xmlfile);
                var headerObj = {
                    "Host": "api.rlcarriers.com",
                    "Content-Type": "text/xml; charset=utf-8",
                    "Content-Length": "length",
                    "SOAPAction": "http://www.rlcarriers.com/GetBillOfLadingPdf"
                };
                var response = https.post({
                    url: 'https://api.rlcarriers.com/1.0.3/BillOfLadingService.asmx?op=GetBillOfLadingPdf',
                    body: Xmlfile,
                    headers: headerObj
                });
                log.debug("responsebol", response)
                if (response.code == 200) {
                    var XML_DATA = response.body;
                    var xmlDoc = xml.Parser.fromString({
                        text: XML_DATA
                    });
                    log.debug("xmlDoc", xmlDoc)
                    var XMLPdfDocument = xmlDoc.getElementsByTagName({
                        tagName: 'PdfDocument'
                    });

                    log.debug("XMLPdfDocument", XMLPdfDocument)
                    var XMLPdfDocument = XMLPdfDocument[0].textContent;
                    log.debug('XMLPdfDocument', XMLPdfDocument)

                    var windo = window.open("", "");
                    var objbuilder = '';
                    objbuilder += ('<html>');
                    objbuilder += (' <head>');
                    objbuilder += ('</head>');
                    objbuilder += ('<body style=" height: 100%;">');
                    objbuilder += ('<iframe width="100%" height="100%"      src="data:application/pdf;base64,');
                    objbuilder += (XMLPdfDocument);
                    
                    objbuilder += ('" type="application/pdf" class="internal">');
                   
                    objbuilder += ('</iframe>');
                    objbuilder += ('</body>');
                    objbuilder += ('</html>');

                   
                    console.log(objbuilder, objbuilder);
                    //window.open(objbuilder);
                    windo.document.write(objbuilder);



                    return true
                }

                


            },

        };

        for (var key in main) {
            if (typeof main[key] === 'function') {
                main[key] = trycatch(main[key], key);
            }
        }

        function trycatch(myfunction, key) {
            return function() {
                try {
                    return myfunction.apply(this, arguments);
                } catch (e) {
                    console.error(e);
                }
            };
        }


        return main;
    });

Leave a comment

Your email address will not be published. Required fields are marked *