Custom Bulk Print Checks

To Print the multiple bill payments we have to create a custom UI to print the transactions as check.Created a custom UI for Multiple checks print as similar to standard “print checks and forms”.

suitelet for creating the custom UI and Print the multiple pdf.

/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget','N/search','N/https','N/file','N/render','N/record','N/runtime'],

    (serverWidget,search,https,file,render,record,runtime) => {
        /**
         * Defines the Suitelet script trigger point.
         * @param {Object} scriptContext
         * @param {ServerRequest} scriptContext.request - Incoming request
         * @param {ServerResponse} scriptContext.response - Suitelet response
         * @since 2015.2
         */
        const onRequest = (scriptContext) => {
            try {
                var request = scriptContext.request;
                var response = scriptContext.response;
                //log.debug("inside onrequest entry point", "inside onrequest entry point");
                if (scriptContext.request.method === 'GET') {

                    var accId = scriptContext.request.parameters.accountId;
                    var checkVal = scriptContext.request.parameters.checkNo;
                    // log.debug("accId", accId);
                    // log.debug("checkVal",checkVal);
                    var form = serverWidget.createForm({
                        title: 'Bulk Print Checks'
                    });

                    form.clientScriptFileId = 12344;
                    //log.debug("form.clientScriptFileId ",form.clientScriptFileId);

                    //search for getting account related to the bill payment
                    var accountSearchObj= search.create({
                        type: "vendorpayment",
                        filters:
                            [
                                // ["account", "anyof", "622", "624"],
                                ["account.type","anyof","Bank"],
                                "AND",
                                ["type", "anyof", "VendPymt"],
                                "AND",
                                ["mainline", "is", "T"],
                                "AND",
                                ["tobeprinted", "is", "T"],

                            ],
                        columns:
                            [
                                search.createColumn({
                                    name: "internalid",
                                    join: "account",
                                    summary: "GROUP",
                                    label: "Internal ID"
                                }),
                                search.createColumn({
                                    name: "name",
                                    join: "account",
                                    sort: search.Sort.ASC,
                                    summary: "GROUP",
                                    label: "Name"
                                })
                            ]
                    });

                    var newobj = [];
                    //var searchLength = searchResultCount;
                    accountSearchObj.run().each(function (result) {
                        // .run().each has a limit of 4,0
                        var searchResultObj = {};
                        searchResultObj.accid = result.getValue(accountSearchObj.columns[0]);
                        searchResultObj.accname = result.getValue(accountSearchObj.columns[1]);
                        newobj.push(searchResultObj);
                        var myData = newobj;

                        newobj = Array.from(new Set(myData.map(JSON.stringify))).map(JSON.parse);
                        return true;
                    });
                    var account = form.addField({
                        id: 'custpage_accountno',
                        type: serverWidget.FieldType.SELECT,
                        label: 'Account'
                    });
                    account.isMandatory = true;
                    //log.debug("account", account);
                    account.addSelectOption({
                        value: "",
                        text: ""
                    });
                    //setting the value of account in the account field
                    for(i=0;i<newobj.length;i++){
                        //log.debug("iii",newobj[i].accounts);
                        var accText= newobj[i].accname
                        var accValue= newobj[i].accid
                        account.addSelectOption({
                            value : accValue,
                            text : accText
                        });
                    }


                    var FirstCheckNumber = form.addField({
                        id: 'check_number',
                        type: serverWidget.FieldType.TEXT,
                        label: 'First Check Number',

                    });
                    FirstCheckNumber.isMandatory = true;
                    //log.debug("check value no",checkVal);

                    if (accId == null || accId == undefined || accId == "") {
                        FirstCheckNumber.defaultValue = ""
                    } else {
                        account.defaultValue= accId;
                        FirstCheckNumber.defaultValue = checkVal
                    }
                    var sublist = form.addSublist({
                        id: 'tran_sublist',
                        type: serverWidget.SublistType.LIST,
                        label: 'Transaction'
                    });
                    sublist.addMarkAllButtons();

                    sublist.addField({
                        id: 'custpage_check',
                        type: serverWidget.FieldType.CHECKBOX,
                        label: 'PRINT'
                    });
                    var internalId = sublist.addField({
                        id : 'custpage_id',
                        label : 'InternalID',
                        type : serverWidget.FieldType.TEXT
                    });
                    internalId.updateDisplayType({displayType: serverWidget.FieldDisplayType.HIDDEN});

                    sublist.addField({
                        id: 'sublist_date',
                        type: serverWidget.FieldType.DATE,
                        label: 'Date'
                    });
                    sublist.addField({
                        id: 'sublist_tran_number',
                        type: serverWidget.FieldType.TEXT,
                        label: 'Transaction Number'
                    });
                    sublist.addField({
                        id: 'sublist_payee',
                        type: serverWidget.FieldType.TEXT,
                        label: 'Payee'
                    });
                    sublist.addField({
                        id: 'sublist_recordtype',
                        type: serverWidget.FieldType.TEXT,
                        label: 'Type'
                    });
                    sublist.addField({
                        id: 'sublist_amount',
                        type: serverWidget.FieldType.CURRENCY,
                        label: 'Amount'
                    });

                    form.addSubmitButton({
                        label: 'Print'
                    });
                    form.addButton({
                        id: 'custpage_cancel',
                        label: 'Cancel',
                        functionName: 'cancelButtonFunction'
                    })

                    // log.debug("success", "success")
                    if (accId) {
                        var paymentSearchValue = vendorPaymentSearch(sublist, accId);
                    }

                    //log.debug("paymentSearchfunction",paymentSearchValue)
                    scriptContext.response.writePage(form);

                }
                else{
                    //post action


                    var lines = scriptContext.request.getLineCount({
                        group: "tran_sublist"
                    });
                    //log.debug("lines",lines);

                    //Getting the internal id from the selected fields to the array
                    var  printpaymentIDListobj = [];
                   //loop for acquire internal id of each bill payment
                    for (var i = 0; i < lines; i++) {
                        var chkboxvalue = scriptContext.request.getSublistValue({
                            group: 'tran_sublist',
                            name: 'custpage_check',
                            line: i
                        });
                        //get only the bill payments when checkbox is true
                        if (chkboxvalue == 'T') {
                            var paymentinternalId = scriptContext.request.getSublistValue({
                                group: 'tran_sublist',
                                name: 'custpage_id',
                                line: i
                            });
                            printpaymentIDListobj.push(paymentinternalId);


                        }
                    }
                    log.debug("internalId list ",printpaymentIDListobj);

                    //calling of search function for values setting inside each pdf template
                    var paymentData = getTransactionData(printpaymentIDListobj);
                    log.debug("paymentData",paymentData);
                    //populate check number in each pdf
                    var checkNum = scriptContext.request.parameters.check_number;
                    log.debug("size of payment data array",paymentData.length);
                    for(var l=0;l<paymentData.length;l++) {
                        paymentData[l].checkNum=Number(checkNum)+l;
                        //setting checknumber and tobeprinted in bill payment record
                        var objRecord = record.submitFields({
                            type: record.Type.VENDOR_PAYMENT,
                            id:  paymentData[l].internalid,
                            values: {
                                tranid: paymentData[l].checkNum,
                                tobeprinted : false

                            },
                            options: {
                                enableSourcing: false,
                                ignoreMandatoryFields : true
                            }
                        });
                        log.debug("printpaymentIDListobj[l]",printpaymentIDListobj[l]);
                        log.debug("paymentData[l].checkNum",paymentData[l].checkNum);

                    }
                    var myTemFile = render.create();
                    var template = 117;
                    myTemFile.setTemplateById(template);

                    myTemFile.addCustomDataSource({
                        format : render.DataSource.OBJECT,
                        alias : 'JSON',
                        data : {billPayments:paymentData}
                    });
                   var checkPdf = myTemFile.renderAsPdf();
                   scriptContext.response.writeFile(checkPdf, true);
                }

            }
            catch (e) {
                log.error(e.message,e);
                log.debug(e.message,e);
            }
            //search for listing the transaction that are need to be printed
            function vendorPaymentSearch(sublist,accId) {
                try {
                    // log.debug("vendorPaymentSearch account value",accId);
                    var vendorpaymentSearchObj = search.create({
                        type: "vendorpayment",
                        filters:
                            [
                                ["account", "anyof", accId.toString()],
                                "AND",
                                ["type", "anyof", "VendPymt"],
                                "AND",
                                ["mainline", "is", "T"],
                                 "AND",
                                ["tobeprinted", "is", "T"]

                            ],
                        columns:
                            [
                                search.createColumn({
                                    name: "trandate",
                                    summary: "GROUP",
                                    label: "Date"
                                }),
                                search.createColumn({
                                    name: "account",
                                    summary: "GROUP",
                                    label: "Account"
                                }),
                                search.createColumn({
                                    name: "entity",
                                    summary: "GROUP",
                                    label: "Name"
                                }),
                                search.createColumn({
                                    name: "type",
                                    summary: "GROUP",
                                    label: "Type"
                                }),
                                search.createColumn({
                                    name: "amount",
                                    summary: "SUM",
                                    function: "absoluteValue",
                                    label: "Amount"
                                }),
                                search.createColumn({
                                    name: "transactionnumber",
                                    summary: "GROUP",
                                    label: "Transaction Number"
                                }),
                                search.createColumn({
                                    name: "internalid",
                                    summary: "GROUP",
                                    label: "Internal ID"
                                })
                            ]
                    });
                    var searchResultCount = vendorpaymentSearchObj.runPaged().count;
                    var paymentsearchArr = [];
                    var searchLength = searchResultCount;
                    vendorpaymentSearchObj.run().each(function (result) {
                        // .run().each has a limit of 4,000 results
                        var resultObj = {};
                        resultObj.accounts = result.getValue({
                            name: "account",
                            summary: "GROUP",
                            label: "Account"

                        });

                        // log.debug("accounts", accounts);
                        resultObj.searchDate = result.getValue({
                            name: "trandate",
                            summary: "GROUP",
                            label: "Date"

                        });
                        //log.debug("searchDate", searchDate);
                        resultObj.payee = result.getText({
                            name: "entity",
                            summary: "GROUP",
                            label: "Name"

                        });
                        //log.debug("payee", payee);
                        resultObj.rectype = result.getValue({
                            name: "type",
                            summary: "GROUP",
                            label: "Type"

                        });

                        resultObj.search_amount = result.getValue({
                            name: "amount",
                            summary: "SUM",
                            label: "Amount"

                        });

                        resultObj.tran_number = result.getValue({
                            name: "transactionnumber",
                            summary: "GROUP",
                            label: "Transaction Number"

                        });
                        resultObj.internalId = result.getValue({
                            name: "internalid",
                            summary: "GROUP",
                            label: "Internal ID"

                        });
                        paymentsearchArr.push(resultObj);
                        return true;
                    });
                    //log.debug("Sublist search Result", paymentsearchArr);
                    //calling of function for setting value in each line transaction inside the custom UI.
                    setValueFunction(paymentsearchArr, accId, sublist, searchLength);
                    return paymentsearchArr;
                }
                catch (e) {
                    log.error(e.message,e);
                    log.debug(e.message,e);
                }


            }
            //function for setting data inside pdf
            function getTransactionData(ids){
                try {
                    var paymentSearchObj = search.create({
                        type: "vendorpayment",
                        filters:
                            [
                                ["type", "anyof", "VendPymt"],
                                "AND",
                                ["internalid", "anyof", ids]
                            ],
                        columns:
                            [
                                search.createColumn({
                                    name: "trandate",
                                    summary: "GROUP",
                                    label: "date"
                                }),
                                search.createColumn({
                                    name: "formulatext",
                                    formula: '{entity}',
                                    summary: "GROUP",
                                    label: "name"
                                }),
                                search.createColumn({
                                    name: "formulatext",
                                    formula: '{appliedToTransaction.type}',
                                    summary: "GROUP",
                                    label: "type"
                                }),
                                search.createColumn({
                                    name: "amount",
                                    join: "appliedToTransaction",
                                    summary: "GROUP",
                                    label: "appliedTranAmount"
                                }),
                                search.createColumn({
                                    name: "trandate",
                                    join: "appliedToTransaction",
                                    summary: "GROUP",
                                    label: "appliedTranDate"
                                }),
                                search.createColumn({
                                    name: "formulatext",
                                    formula: '{account}',
                                    summary: "GROUP",
                                    label: "account"
                                }),
                                search.createColumn({
                                    name: "amount",
                                    summary: "GROUP",
                                    function: "absoluteValue",
                                    label: "amount"
                                }),
                                search.createColumn({
                                    name: "internalid",
                                    join: "appliedToTransaction",
                                    summary: "GROUP",
                                    label: "billinternalid"
                                }),

                                search.createColumn({
                                    name: "tranid",
                                    join: "appliedToTransaction",
                                    summary: "MAX",
                                    label: "tranid"
                                }),
                                search.createColumn({
                                    name: "internalid",
                                    summary: "GROUP",
                                    sort: search.Sort.ASC,
                                    label: "internalid"
                                }),
                                search.createColumn({
                                    name: "memo",
                                    summary: "MAX",
                                    label: "memo"
                                }),

                                search.createColumn({
                                    name: "appliedtolinkamount",
                                    summary: "GROUP",
                                    label: "appliedtolinkamount"
                                }),
                                search.createColumn({
                                    name: "formulatext",
                                    summary: "GROUP",
                                    formula: "CASE WHEN ABS({amount})=0 THEN 'ZERO' ELSE TO_CHAR(TO_DATE(TO_CHAR(TRUNC(ABS({amount}), 0)),'J'),'JSP') || ' And ' || DECODE((CASE WHEN LENGTH(TO_CHAR(REGEXP_REPLACE(ABS({amount}), '^[0-9]+\\.', ''))) = 1 THEN TO_CHAR(REGEXP_REPLACE(ABS({amount}), '^[0-9]+\\.', '')) || '0/100' ELSE TO_CHAR(REGEXP_REPLACE(ABS({amount}), '^[0-9]+\\.', '')) || '/100' END),ROUND(ABS({amount}))||'/100','00/100',(CASE WHEN LENGTH(TO_CHAR(REGEXP_REPLACE(ABS({amount}), '^[0-9]+\\.', ''))) = 1 THEN TO_CHAR(REGEXP_REPLACE(ABS({amount}), '^[0-9]+\\.', '')) || '0/100' ELSE TO_CHAR(REGEXP_REPLACE(ABS({amount}), '^[0-9]+\\.', '')) || '/100' END)) END",
                                    label: "inwords"
                                }),
                                search.createColumn({
                                    name: "billattention",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "attention"
                                }),
                                search.createColumn({
                                    name: "billaddressee",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "addressee"
                                }),
                                search.createColumn({
                                    name: "billaddress1",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "address1"
                                }),
                                search.createColumn({
                                    name: "billcity",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "city"
                                }),
                                search.createColumn({
                                    name: "billstate",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "state"
                                }),
                                search.createColumn({
                                    name: "billzipcode",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "zipcode"
                                }),
                                search.createColumn({
                                    name: "billcountry",
                                    join: "vendor",
                                    summary: "MAX",
                                    label: "country"
                                })
                               
                            ]
                    });

                    var printPaymentArr = [], mapArray = [];
                    log.debug("paymentSearchObj",paymentSearchObj);
                    paymentSearchObj.run().each(function (result) {
                        var singleLine = {};
                        for (var i = 0; i < paymentSearchObj.columns.length; i++) {
                            singleLine[paymentSearchObj.columns[i].label] = result.getValue(paymentSearchObj.columns[i])
                        }

                        log.debug("amount in word format",singleLine.inwords);
                        log.debug("amount in word format lower",singleLine.inwords.toLowerCase());

                        singleLine.inwords = singleLine.inwords.toLowerCase();
                        //singleLine.inwords = singleLine.inwords.
                        log.debug("amount in word format",singleLine.inwords);
                        singleLine.amount = numberWithCommas(singleLine.amount);
                        singleLine.appliedtolinkamount = numberWithCommas(singleLine.appliedtolinkamount);
                        singleLine.appliedTranAmount =  numberWithCommas(singleLine.appliedTranAmount);

                        singleLine.memo = htmlSpecialChars(singleLine.memo);
                        singleLine.tranid = htmlSpecialChars(singleLine.tranid);
                        singleLine.name = htmlSpecialChars(singleLine.name);
                        singleLine.type = htmlSpecialChars(singleLine.type);
                        singleLine.attention = htmlSpecialChars(singleLine.attention);
                        singleLine.addressee = htmlSpecialChars(singleLine.addressee);
                        singleLine.address1 = htmlSpecialChars(singleLine.address1);
                        singleLine.city = htmlSpecialChars(singleLine.city);
                        singleLine.state = htmlSpecialChars(singleLine.state);
                        singleLine.zipcode = htmlSpecialChars(singleLine.zipcode);
                        singleLine.country = htmlSpecialChars(singleLine.country);
                        singleLine.account = htmlSpecialChars(singleLine.account);
                        singleLine.inwords = htmlSpecialChars(singleLine.inwords);

                        var currentTransactionIndex = mapArray.indexOf(singleLine.internalid);
                        log.debug("currentTransactionIndex", currentTransactionIndex);
                        if (currentTransactionIndex == -1) {
                            // transaction not in Object
                            if (singleLine.type != '- None -') {
                                // applied transaction line in the pdf
                                log.debug("first if");

                                printPaymentArr.push({appliedTransactions: [singleLine]})
                                log.debug("printPaymentArr........", printPaymentArr);

                            } else {
                                // Set body fields in the pdf
                                log.debug("Set body fields");
                                singleLine.appliedTransactions = [];
                                printPaymentArr.push(singleLine);
                                log.debug("else body part printPay........", printPaymentArr);


                            }
                            mapArray.push(singleLine.internalid)
                            log.debug("mapArray", mapArray);
                        } else {
                            if (singleLine.type != '- None -') {
                                // applied transaction line
                                log.debug("second if condition");
                                printPaymentArr[currentTransactionIndex].appliedTransactions.push(singleLine);
                            } else {

                                // body part
                                printPaymentArr[currentTransactionIndex].internalid = singleLine.internalid;
                                printPaymentArr[currentTransactionIndex].amount = singleLine.amount;
                                printPaymentArr[currentTransactionIndex].inwords = singleLine.inwords;
                                printPaymentArr[currentTransactionIndex].name = singleLine.name;
                                printPaymentArr[currentTransactionIndex].account = singleLine.account;
                                printPaymentArr[currentTransactionIndex].date = singleLine.date;
                                if (singleLine.memo == '- None -') {
                                    //log.debug("memo null");
                                    printPaymentArr[currentTransactionIndex].memo = '';
                                } else {
                                    //log.debug("memo not null");
                                    printPaymentArr[currentTransactionIndex].memo = singleLine.memo;
                                }
                                printPaymentArr[currentTransactionIndex].attention = singleLine.attention;
                                printPaymentArr[currentTransactionIndex].addressee = singleLine.addressee;
                                printPaymentArr[currentTransactionIndex].address1 = singleLine.address1;
                                printPaymentArr[currentTransactionIndex].city = singleLine.city;
                                printPaymentArr[currentTransactionIndex].state = singleLine.state;
                                printPaymentArr[currentTransactionIndex].zipcode = singleLine.zipcode;
                                printPaymentArr[currentTransactionIndex].country = singleLine.country;

                            }
                        }

                        return true;
                    })
                    log.debug("return printPaymentArr", printPaymentArr);
                    return printPaymentArr;
                }
                catch (e) {
                    log.error(e.message,e);
                    log.debug(e.message,e);
                }

            }
            function numberWithCommas(x) {
                var parts = x.toString().split(".");
                parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
                return parts.join(".");
            }

            //function for remove special characters
            function htmlSpecialChars(unsafe) {
                //log.debug("xml error solu",unsafe.replace(/&/g, "&amp;"));
                return unsafe
                    .replace(/&/g, "&amp;")
                    .replace(/</g, "&lt;")
                    .replace(/>/g, "&gt;")
                    .replace(/"/g, "&quot;")
                    .replace(/'/g, "&apos;");
            }

            function setValueFunction(paymentSearchvalue,accId,sublist, j) {
                try {

                    //log.debug("setValueFunctionaccount value getting", accId);
                    //log.debug("setValueFunction payment account", paymentSearchvalue[i].accounts);
                    for (var i = 0; i < j; i++) {

                        sublist.setSublistValue({
                            id: 'custpage_check',
                            line: i,
                            value: 'F'
                        });
                        sublist.setSublistValue({
                            id: 'custpage_id',
                            line: i,
                            value: paymentSearchvalue[i].internalId
                        });
                        sublist.setSublistValue({
                            id: 'sublist_date',
                            line: i,
                            value: paymentSearchvalue[i].searchDate
                        });
                        sublist.setSublistValue({
                            id: 'sublist_tran_number',
                            line: i,
                            value: paymentSearchvalue[i].tran_number
                        });
                        sublist.setSublistValue({
                            id: 'sublist_payee',
                            line: i,
                            value: paymentSearchvalue[i].payee
                        });

                        sublist.setSublistValue({
                            id: 'sublist_recordtype',
                            line: i,
                            value: 'vendor'
                        });
                        sublist.setSublistValue({
                            id: 'sublist_amount',
                            line: i,
                            value: paymentSearchvalue[i].search_amount
                        });
                    }

                }
                catch (e) {
                    log.error(e.message,e);
                    log.debug(e.message,e);
                }



            }
            //get runtime usage of the script
            var scriptObj = runtime.getCurrentScript();
            log.debug('Remaining governance units: ' + scriptObj.getRemainingUsage());
        }
        return {onRequest}
    });

client script

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/record','N/url','N/https','N/currentRecord'],

function(record,url,https,currentRecord) {
    
    /**
     * Function to be executed after page is initialized.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
     *
     * @since 2015.2
     */
    function pageInit(scriptContext) {
        console.log("in");
    }
    /**
     * Function to be executed when field is changed.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.sublistId - Sublist name
     * @param {string} scriptContext.fieldId - Field name
     * @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
     * @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
     *
     * @since 2015.2
     */
    function cancelButtonFunction(){
        try {
            console.log("cancel button inside");
            window.location.href = 'https://4248794-sb1.app.netsuite.com/app/center/card.nl?sc=-29&whence=';
        }
        catch (e) {
            log.error(e.message,e);
            log.debug(e.message,e);
        }

    }
    function saveRecord(scriptContext){
        try {

            var RecordObj = currentRecord.get();
            var lineCount = RecordObj.getLineCount({
                sublistId: "tran_sublist"
            });
            var lineNumber = RecordObj.findSublistLineWithValue({
                sublistId: 'tran_sublist',
                fieldId: 'custpage_check',
                value: "T"
            });
            if (lineNumber == -1) {
                alert("Please choose atleast one transaction to print");
                return false;
            }
            var applycount = 0;
            var upperBound = 30;
            for (i = 0; i < lineCount; i++) {
                var checkbox = RecordObj.getSublistValue({
                    sublistId: "tran_sublist",
                    fieldId: "custpage_check",
                    line: i
                })
                if (checkbox == 'T' || checkbox == true) {
                    applycount += 1;
                    if (applycount > upperBound) {
                        alert("Please select transaction count less than " + upperBound);
                        return false;
                    }
                }
            }
            return true;
        }
        catch (e) {
            log.error(e.message,e);
            log.debug(e.message,e);
        }
    }


    function fieldsChanged(scriptContext) {
        try {
            if (scriptContext.fieldId === 'custpage_accountno') {
                console.log("inside client script");
                var currentRecord = scriptContext.currentRecord;

                var accountField = currentRecord.getValue({
                    fieldId: "custpage_accountno"
                });
                console.log("accountField:", accountField);
                if(accountField == null || accountField == undefined || accountField == ''){
                    currentRecord.setValue({
                        fieldId : 'check_number',
                        value:''
                    });
                    var suiteletURL = url.resolveScript({
                        scriptId: 'customscript_custom_check_forms',
                        deploymentId: 'customdeploy_custom_check_forms'

                    });
                    window.onbeforeunload = null;
                    window.location.href = suiteletURL;
                    console.log("success");


                }
                else if(accountField){
                    console.log("accountField is true");
                    // var accountLookup = search.lookupFields({
                    //     type:search.Type.ACCOUNT,
                    //     id:accountField,
                    //     columns : [''],
                    // });
                    var accountRec = record.load({
                        type: record.Type.ACCOUNT,
                        id: accountField,
                        isDynamic: true,
                    });
                    var accRecId = accountRec.id;
                    console.log("accRecId", accRecId);
                    console.log("accountRec", accountRec);
                    var checknumber = accountRec.getValue({
                        fieldId: 'curdocnum'
                    });
                    console.log("checknumber", checknumber);
                    console.log("endif");
                    if (accountField == accRecId) {
                        var accDetails = {"accountId": accountField, "checkNo": checknumber}
                        console.log("accDetails", accDetails);
                        var suiteletURL = url.resolveScript({
                            scriptId: 'customscript_custom_check_forms',
                            deploymentId: 'customdeploy_custom_check_forms',
                            params: {
                                "accountId": accountField,
                                "checkNo": checknumber
                            }
                        });
                        console.log("suiteletURL", suiteletURL);
                        window.onbeforeunload = null;
                        //window.location.reload= true;
                        window.location.href = suiteletURL;
                        console.log("success");

                    }

                }
                else
                    window.location.reload();

            }
        } catch (e) {
            log.debug("clientscript error", e);
        }


    }

    return {
        cancelButtonFunction:cancelButtonFunction,
        pageInit: pageInit,
        fieldChanged: fieldsChanged,
        saveRecord: saveRecord

    };
    
});

advanced pdf template

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdfset>
<#list JSON.billPayments as record>
<pdf>
<head>
	<link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
	<#if .locale == "zh_CN">
		<link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
	<#elseif .locale == "zh_TW">
		<link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
	<#elseif .locale == "ja_JP">
		<link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
	<#elseif .locale == "ko_KR">
		<link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
	<#elseif .locale == "th_TH">
		<link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
	</#if>
    <style type="text/css">* {
		<#if .locale == "zh_CN">
			font-family: NotoSans, NotoSansCJKsc, sans-serif;
		<#elseif .locale == "zh_TW">
			font-family: NotoSans, NotoSansCJKtc, sans-serif;
		<#elseif .locale == "ja_JP">
			font-family: NotoSans, NotoSansCJKjp, sans-serif;
		<#elseif .locale == "ko_KR">
			font-family: NotoSans, NotoSansCJKkr, sans-serif;
		<#elseif .locale == "th_TH">
			font-family: NotoSans, NotoSansThai, sans-serif;
		<#else>
			font-family: NotoSans, sans-serif;
		</#if>
		}
		td p { align:left }
</style>
</head>
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
    <div style="position: relative;font-family: Helvetica,sans-serif;top= -11pt;height: 250pt;width: 612pt;page-break-inside: avoid;font-size: 8pt;">
<table style="position: absolute;overflow: hidden;left: 496pt;top: 8pt;height: 7pt;width: 85pt;font-size: 5pt;"><tr>
	<td align="center">${record.checkNum}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 466pt;top: 34pt;height: 18pt;width: 108pt;"><tr>
	<td>${record.date}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 50pt;top: 69pt;height: 18pt;width: 393pt;"><tr>
	<td>${record.name}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 463pt;top: 69pt;height: 18pt;width: 111pt;"><tr>
	<td>**<#if (record.amount?length > 0)>$${record.amount}<#else>$${record.amount}</#if></td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 2pt;top: 93pt;height: 18pt;width: 572pt;"><tr>
	<td>${record.inwords}*********************************************************************</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 37pt;top: 122pt;height: 80pt;width: 537pt;"><tr>
	<td>${record.attention}<br/>${record.addressee} <br/>${record.address1}<br/>${record.city} ${record.state} ${record.zipcode}<br/> ${record.country}</td>
	</tr></table>
 <#assign length=record.appliedTransactions?size>

<table style="position: absolute;overflow: hidden;left: 2pt;top: 178pt;height: 18pt;width: 572pt;">

  <tr>
  <td>
       <#if length lt 2>
      ${record.memo}
         <#else>&nbsp;
         </#if>
         </td>
	</tr>
    </table>
</div>

<div style="position: relative;font-family: Helvetica,sans-serif;height: 250pt;width: 612pt;page-break-before: avoid;font-size: 8pt;">
<table style="position: absolute;overflow: hidden;left: 403pt;top: -16pt;height: 7pt;width: 40pt;font-size: 5pt;"><tr>
	<td align="center">${record.checkNum}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 412pt;top: -2pt;height: 13pt;width: 70pt;"><tr>
	<td>${record.date}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 36pt;top: -2pt;height: 13pt;width: 187pt;"><tr>
	<td>${record.name}</td>
	</tr></table>
<#if record.item?has_content || record.expense?has_content>

<table style="position: absolute;overflow: hidden;left: 36pt;top: 90pt;width: 436pt;"><#list record.expense as expense><tr>
	<td>${expense.account}</td>
	<td>${expense.date}</td>
	<td>${expense.description}</td>
	<td align="right">${expense.amount}</td>
	</tr>
	</#list><#list record.item as item>
	<tr>
	<td>&nbsp;</td>
	<td>${item.date}</td>
	<td>${item.item}, ${item.description}</td>
	<td align="right">${item.amount}</td>
	</tr>
	</#list></table>
</#if>

<table style="width: 75%; position: absolute;overflow: hidden;left: 2pt;top:11pt;height: 18pt;"><!-- start apply sublist -->
<thead>
	<tr>
	<th align="left" colspan="3" line-height="110%" margin-left="2pt">Date</th>
	<th align="center" colspan="5" line-height="110%">Type</th>
	<th align="right" colspan="3" line-height="110%">Ref No.</th>
	<th align="right" colspan="3" line-height="110%">Orig. Amt.</th>
	<th align="right" colspan="3" line-height="110%" margin-right="2pt">Amt. Due</th>
	<th align="right" colspan="3" line-height="110%">Disc. Taken</th>
	<th align="right" colspan="3" line-height="110%" margin-right="2pt">Payment</th>
	</tr>
</thead>
  <#assign length=0>
  <#list record.appliedTransactions as apply>
   <#assign length=length+1/>
     <#if length lt 14>
  <tr>
	<td align="left" colspan="3" line-height="120%">${apply.appliedTranDate}</td>
	<td align="center" colspan="5" line-height="120%">${apply.type}</td>
	<td align="right" colspan="3" line-height="120%">${apply.tranid}</td>
	<td align="right" colspan="3" line-height="120%">$${apply.appliedTranAmount}</td>
	<td align="right" colspan="3" line-height="120%">$${apply.appliedtolinkamount}</td>
	<td align="right" colspan="3" line-height="120%">${apply.disc}</td>
	<td align="right" colspan="3" line-height="120%">$${apply.appliedtolinkamount}</td>
	</tr>
       </#if>
	</#list><!-- end apply --></table>

<table style="position: absolute;overflow: hidden;left: 466pt;top: 204pt;height: 13pt;width: 67pt;"><tr>
	<td>${record.account}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 148pt;top: 204pt;height: 13pt;width: 325pt;"><tr>
	<td>
       <#if length lt 2>
      ${record.memo}
         <#else>&nbsp;
         </#if>
         </td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 9pt;top: 204pt;height: 13pt;width: 134pt;"><tr>
	<td>$${record.amount}</td>
	</tr></table>
</div>

<div style="position: relative;font-family: Helvetica,sans-serif;height: 250pt;width: 612pt;page-break-before: avoid;font-size: 8pt;">
<table style="position: absolute;overflow: hidden;left: 403pt;top: -16pt;height: 7pt;width: 40pt;font-size: 5pt;"><tr>
	<td align="center">${record.checkNum}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 412pt;top: -2pt;height: 13pt;width: 70pt;"><tr>
	<td>${record.date}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 36pt;top: -2pt;height: 13pt;width: 187pt;"><tr>
	<td>${record.name}</td>
	</tr></table>
<#if record.item?has_content || record.expense?has_content>

<table style="position: absolute;overflow: hidden;left: 36pt;top: 90pt;width: 436pt;"><#list record.expense as expense><tr>
	<td>${expense.account}</td>
	<td>${expense.date}</td>
	<td>${expense.description}</td>
	<td align="right">${expense.amount}</td>
	</tr>
	</#list><#list record.item as item>
	<tr>
	<td>&nbsp;</td>
	<td>${item.date}</td>
	<td>${item.item}, ${item.description}</td>
	<td align="right">${item.amount}</td>
	</tr>
	</#list></table>
</#if>

<table style="width: 75%; position: absolute;overflow: hidden;left: 2pt;top:11pt;height: 18pt;"><!-- start apply sublist -->
<thead>
	<tr>
	<th align="left" colspan="3" line-height="110%" margin-left="2pt">Date</th>
	<th align="center" colspan="5" line-height="110%">Type</th>
	<th align="right" colspan="3" line-height="110%">Ref No.</th>
	<th align="right" colspan="3" line-height="110%">Orig. Amt.</th>
	<th align="right" colspan="3" line-height="110%" margin-right="2pt">Amt. Due</th>
	<th align="right" colspan="3" line-height="110%">Disc. Taken</th>
	<th align="right" colspan="3" line-height="110%" margin-right="2pt">Payment</th>
	</tr>
</thead>
  <#assign length=0>
  <#list record.appliedTransactions as apply>
   <#assign length=length+1/>
     <#if length lt 14>
  <tr>
	<td align="left" colspan="3" line-height="120%">${apply.appliedTranDate}</td>
	<td align="center" colspan="5" line-height="120%">${apply.type}</td>
	<td align="right" colspan="3" line-height="120%">${apply.tranid}</td>
	<td align="right" colspan="3" line-height="120%">$${apply.appliedTranAmount}</td>
	<td align="right" colspan="3" line-height="120%">$${apply.appliedtolinkamount}</td>
	<td align="right" colspan="3" line-height="120%">${apply.disc}</td>
	<td align="right" colspan="3" line-height="120%">$${apply.appliedtolinkamount}</td>
	</tr>
       </#if>
	</#list><!-- end apply --></table>
<table style="position: absolute;overflow: hidden;left: 466pt;top: 204pt;height: 13pt;width: 67pt;"><tr>
	<td>${record.account}</td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 148pt;top: 204pt;height: 13pt;width: 325pt;"><tr>
	<td> <#if length lt 2>
      ${record.memo}
         <#else>&nbsp;
         </#if></td>
	</tr></table>

<table style="position: absolute;overflow: hidden;left: 9pt;top: 204pt;height: 13pt;width: 134pt;"><tr>
	<td>$${record.amount}</td>
	</tr></table>
</div>
</body>
</pdf>
</#list>
  </pdfset>

Leave a comment

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