Customer Deposit PDF Print

Make a Custom Button in Customer Deposit Record And Clicking on the Button it will Render a Advanced Pdf Template

User Event Script For Button Creation

function beforeLoad(context) {
            if(context.type == 'view'){
           context.form.addButton({
            id: "custpage_jj_drf_139_vgm_button",
            label: "Customer Deposit Print",
            functionName : "onButtonClick"
    
           });
        }
        context.form.clientScriptModulePath = "SuiteScripts/Jobin and Jismi IT Services/EX-40/EX-143CL.js"
    }
        return {
            beforeLoad: beforeLoad,
        };

Client Script For UE Function Triggering

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) {},
            onButtonClick: function() {
                var vgmid = { entId: currentRecord.get().id }

                var CreateLinkUrl = url.resolveScript({
                    scriptId: "customscript36",
                    deploymentId: "customdeploy1",
                    returnExternalUrl: false,
                    params: vgmid
                });

                var windowCreatelink = window.open(CreateLinkUrl);
            },

        };

        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;
    });

Suitelet For Pdf Rendering

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
/*************************************************************************************************************************
* CLIENTNAME:Diamond Roller Flour Mills Pvt. Ltd
* DRF-139
* Annexure-c print button
* **********************************************************************************************************************
* Date :27/03/2020
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This Script is  to create print out of Annexure-c
* Date created : 27/03/2020
*
* REVISION HISTORY
*
* Revision 1.0 ${25/04/2020} Abin: created
*
**************************************************************************************************************************/
define(['N/record', 'N/search', 'N/ui/serverWidget', 'N/render', 'N/email', 'N/file', 'N/encode', 'N/task', 'N/url', 'N/redirect'],

    function (record, search, serverWidget, render, email, file, encode, task, url, redirect) {





        function vgmRecord(context) {



            try {
                // var vgm = context.request.parameters.vgmid;
                log.debug("vgmid");
                
                var myFile = render.create();
                var template = 'CUSTTMPL_110_4071463_559';
                myFile.setTemplateByScriptId(template);
                var cus=record.load({
                    type: record.Type.CUSTOMER_DEPOSIT,
                    id: 73029
                });
               var said= cus.getValue({
                    fieldId: 'salesorder'
                });
                log.debug("salesid",said);

                myFile.addRecord('record', record.load({
                    type: record.Type.CUSTOMER_DEPOSIT,
                    id: 73029
                }));
                myFile.addRecord('sale', record.load({
                    type: record.Type.SALES_ORDER,
                    id: said
                }));
                var vgmFile = myFile.renderAsPdf();
                context.response.writeFile(vgmFile, true);
            }


            catch (e) {
                log.debug('catch error::', e)

            }
        }

        var main = {

            onRequest: function (context) {

                vgmRecord(context)

            }
        };
        return main;

    });

Leave a comment

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