NetSuite SuiteScript 2.0如何从UserEvent按钮创建银行存款单(suitelet函数)

NetSuite SuiteScript 2.0如何从UserEvent按钮创建银行存款单(suitelet函数),netsuite,suitescript2.0,Netsuite,Suitescript2.0,我是一名非开发人员,对NetSuite和SuiteScript是全新的,我正在一路蹒跚前行 问题:对于每个存款记录,我需要创建一个可打印的pdf,列出该记录上的每个付款(银行存款单)。我想在自定义按钮上调用此pdf,以显示在我可以打印的新窗口中。我不需要将文档保存在文件柜中 1。现在我有一个UserEvent按钮,它在查看和编辑模式下显示在存款上 定义([],函数(){ /** *@NApiVersion 2.x *@NScriptType UserEventScript */ var导出={

我是一名非开发人员,对NetSuite和SuiteScript是全新的,我正在一路蹒跚前行

问题:对于每个存款记录,我需要创建一个可打印的pdf,列出该记录上的每个付款(银行存款单)。我想在自定义按钮上调用此pdf,以显示在我可以打印的新窗口中。我不需要将文档保存在文件柜中

1。现在我有一个UserEvent按钮,它在查看和编辑模式下显示在存款上

定义([],函数(){
/**
*@NApiVersion 2.x
*@NScriptType UserEventScript
*/
var导出={};
加载前函数(上下文){
context.form.addButton({
id:“客户页\打印存款单”,
标签:“打印存款单”,
函数名:“onButtonClick”
});
context.form.clientScriptModulePath=“SuiteScripts/depositSlips/customDepositSlipButton.js”
}
exports.beforeLoad=beforeLoad;
出口退税;

});您的Suitelet需要接受一个参数,以确定要打印的记录:

function onRequest(context) {
    var id = context.request.parameters.custom_id;
    if (!id) {
        context.response.write('The parameter "custom_id" is required');
        return;
    }
    var xmlString = generateXml(id);
    context.response.renderPdf({ xmlString: xmlString });
}

function generateXml(id) {
    var depositRecord = record.load({ type: record.Type.DEPOSIT, id: id });
    var xml = ...
    return xml;
}
然后,客户端脚本可以打开Suitelet页面,传入当前记录的内部Id(确保导入
N/url
N/currentRecord
模块):


免责声明:以上代码未经测试,可能包含语法错误

我也在尝试同样的事情。我的终于可以工作了,请尝试将xml字符串更改为:

    var xml = '<?xml version="1.0"?>\n<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">\n<pdf>';
    xml += '\n<body font-size="18">\n';
    xml += '<table width="100%" align="center">\n';
    xml += '<tr>\n';
    xml += '<td>Deposit Number: ' + depositRecord.getValue({fieldId: 'tranid'}) + '</td>\n';
    xml += '</tr>\n';
    xml += '<tr>\n';
    xml += '<td>Date: ' + depositRecord.getValue({fieldId: 'trandate'}) + '</td>\n';
    xml += '</tr>\n';
    xml += '<tr>\n';
    xml += '<td>Total: ' + depositRecord.getValue({fieldId: 'total'}) + '</td>\n';
    xml += '</tr>\n';
    xml += '<tr>\n';
    xml += '<td>Posting Period: ' + depositRecord.getText({fieldId: 'postingperiod'}) + '</td>\n';
    xml += '</tr>\n';
    xml += '</table>\n';

    xml += '<br /><br />\n';

    xml += '<table width="100%" align="center">\n';
    xml += '<thead>\n';
    xml += '<tr>\n';
    xml += '<th>Date</th>\n';
    xml += '<th>ID</th>\n';
    xml += '<th>Customer</th>\n';
    xml += '<th>Payment Amount</th>\n';
    xml += '<th>Transaction Amount</th>\n';
    xml += '<th>Transaction Type</th>\n';
    xml += '<th>Payment Method</th>\n';
    xml += '</tr>\n';
    xml += '</thead>\n';
    xml += '<tbody>\n';

    for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'payment'})); i++){
        if (depositRecord.getSublistText({sublistId: 'payment', fieldId: 'deposit', line: i}) == 'T'){
            xml += '<tr>\n';
            xml += '<td>' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docdate', line: i}) + '</td>\n';
            xml += '<td>' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docnumber', line: i}) + '</td>\n';
            xml += '<td>' + depositRecord.getSublistText({sublistId: 'payment', fieldId: 'entity', line: i}) + '</td>\n';
            xml += '<td>' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'paymentamount', line: i}) + '</td>\n';
            xml += '<td>' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'transactionamount', line: i}) + '</td>\n';
            xml += '<td>' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'type', line: i}) + '</td>\n';
            xml += '<td>' + depositRecord.getSublistText({sublistId: 'payment', fieldId: 'paymentmethod', line: i}) + '</td>\n';
            xml += '</tr>\n';
        }
    }

    xml += '</tbody>\n';
    xml += '</table>\n';
    xml += '</body>';
    xml += '\n</pdf>'; 
var xml='\n\n';
xml+='\n\n';
xml+='\n';
xml+='\n';
xml++='存款编号:'+DepostRecord.getValue({fieldId:'tranid'})+'\n';
xml+='\n';
xml+='\n';
xml++='日期:'+DepostRecord.getValue({fieldId:'trandate'})+'\n';
xml+='\n';
xml+='\n';
xml++='Total:'+depositRecord.getValue({fieldId:'Total'})+'\n';
xml+='\n';
xml+='\n';
xml++='过帐期间:'+DepostRecord.getText({fieldId:'过帐期间'})+'\n';
xml+='\n';
xml+='\n';
xml+='

\n'; xml+='\n'; xml+='\n'; xml+='\n'; xml+='Date\n'; xml+='ID\n'; xml+='Customer\n'; xml+='付款金额\n'; xml+='交易金额\n'; xml+='事务类型\n'; xml+='付款方式\n'; xml+='\n'; xml+='\n'; xml+='\n'; 对于(var i=0;i

并查看这是否修复了解析XML错误。

使用前面两个答案中的输入,下面是完整的工作解决方案和结果的屏幕截图:

步骤1)客户端脚本为自定义按钮建立单击处理程序,这将获取当前记录的id并将其传递给在新窗口中执行的suitelet

define(['N/url', 'N/currentRecord'], function (url, currentRecord) {
/**
  * 
  * @NApiVersion 2.x
  * @NScriptType ClientScript
  * @appliedtorecord deposit
  */
var exports = {};
/**
  * <code>pageInit</code> event handler
  * 
  * @gov XXX
  * 
  * @param context
  *             {Object}
  * @param context.mode
  *             {String} The access mode of the current record. will be one of
  *                 <ul>
  *                 <li>copy</li>
  *             <li>create</li>
  *             <li>edit</li>
  *             </ul>
  * 
  * @return {void}
  * 
  * @static
  * @function pageInit
  */
 function pageInit(context) {
     // TODO
 }
 function onButtonClick() {
  var suiteletUrl = url.resolveScript({
    scriptId: 'customscript_depositslip_pdf', //the script id of my suitelet
    deploymentId: 'customdeploy_depositslip_pdf', //the deployment id of my suitelet
    returnExternalUrl: false,
    params: {
        custom_id: currentRecord.get().id,
    },
 });
 window.open(suiteletUrl);
 }
 exports.onButtonClick = onButtonClick;
 exports.pageInit = pageInit;
 return exports;
 });
步骤2)用户事件脚本,创建一个在我的存款记录的编辑和查看模式下都可见的自定义按钮,并从我的客户端脚本调用单击处理程序

define([], function () {
/**
  * 
  * @NApiVersion 2.x
  * @NScriptType UserEventScript
  * @appliedtorecord deposit
  */
 var exports = {};
 /**
  * <code>beforeLoad</code> event handler
  * 
  * @gov 0
  * 
  * @param context
  *             {Object}
  * @param context.newRecord
  *             {record} the new record being loaded
  * @param context.type
  *             {UserEventType} the action that triggered this event
  * @param context.form
  *             {form} The current UI form
  * 
  * @return {void}
  * 
  * @static
  * @function beforeLoad
  */
  function beforeLoad(context) {
    context.form.addButton({
        id: "custpage_printdepositslip",
        label: "Print Deposit Slip",
        functionName: "onButtonClick"
    });
    context.form.clientScriptModulePath = "SuiteScripts/ss2-add-button/customDepositSlipButton.js"
    }
  exports.beforeLoad = beforeLoad;
  return exports;
 });
步骤3)Suitelet脚本,用于根据当前存款的记录id(单击按钮的位置)从xml创建自定义表单,该表单从存款子列表中提取信息,并将其返回到pdf格式的有组织表格中,如果表格需要多个页面,则在每页上保留页眉和页脚部分

define(['N/render', 'N/record', 'N/xml', 'N/format'],
function(render, record, xml, format) {
 /**
    *@NApiVersion 2.x
    * @NScriptType Suitelet
    * @appliedtorecord deposit
    */
 /**
    * <code>onRequest</code> event handler
    * @gov 0
    * 
    * @param request
    *           {Object}
    * @param response
    *           {String}
    * 
    * @return {void}
    * 
    * @static
    * @function onRequest
    * @function generateXml
    */
function onRequest(context) {
    var id = context.request.parameters.custom_id;
    if (!id) {
        context.response.write('The parameter "custom_id" is required');
        return;
    }
    var xmlString = generateXml(id);
    context.response.renderPdf({ xmlString : xmlString });
}
function generateXml(id) {
      var depositRecord = record.load({ type: record.Type.DEPOSIT, id: id });
      var totes = depositRecord.getValue('total');
      var totally = format.format({value:totes, type:format.Type.CURRENCY});
      var fulldate = depositRecord.getValue('trandate');
      var mmdddate = format.format({value:fulldate, type:format.Type.DATE});
      var xml='<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">\n<pdf>\n<head>\n<macrolist>\n<macro id="nlheader">\n';
        xml += '<table width="100%" align="center" style="font-size:11px;">\n';
        xml += '<tr>\n';
        xml += '<td><b>Deposit Number:</b> ' + depositRecord.getValue('tranid') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Date:</b> ' + mmdddate + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Account:</b> ' + depositRecord.getText('account') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Total:</b> ' + totally + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Posting Period:</b> ' + depositRecord.getText('postingperiod') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Memo:</b> ' + depositRecord.getText('memo') + '</td>\n';
        xml += '</tr>\n';
        xml += '</table>\n';
        xml += '</macro>\n<macro id="nlfooter">\n<table style="width: 100%;">\n<tr>\n<td align="right" style="padding: 0; font-size:8pt;">\n<p align="right" text-align="right" ><br /><pagenumber/> of <totalpages/></p>\n</td>\n</tr>\n</table>\n</macro>\n</macrolist>\n</head>\n<body header="nlheader" header-height="13%" footer="nlfooter" footer-height="10pt" padding="0.375in 0.5in 0.5in 0.5in"  style="font:10px arial, sans-serif; text-align:left;">\n';
        xml += '<table width="100%" align="center" cellpadding="4" cellspacing="0" style="text-align:left; border-left:1px solid #ccc; border-right:1px solid #ccc;">\n';
        xml += '<thead>\n';
        xml += '<tr style="border:1px solid #ccc; background-color:#efefef;">\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Date</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>ID</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Customer</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Payment Method</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Type</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Ref No.</b></th>\n';
        xml += '<th><b>Amount</b></th>\n';
        xml += '</tr>\n';
        xml += '</thead>\n';
        xml += '<tbody>\n';
        for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'payment'})); i++)
        {
        var amt = depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'paymentamount', line: i});
        var payamt = format.format({value:amt, type:format.Type.CURRENCY});
        var longdate = depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docdate', line: i});
        var shortdate = format.format({value:longdate, type:format.Type.DATE});
        if (depositRecord.getSublistText({sublistId: 'payment', fieldId: 'deposit', line: i}) == 'T')
        {
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' + shortdate  + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docnumber', line: i}) + '</td>\n';
        var name= depositRecord.getSublistText({sublistId: 'payment', fieldId: 'entity', line: i})
                var andName = name.match('&')
                if(andName){
                var newName = name.replace("&", "&amp;");
                xml += '<td style="border-right:1px solid #ccc;">' + newName + '</td>\n';
                }
                else 
                    xml += '<td style="border-right:1px solid #ccc;">' + name + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistText({sublistId: 'payment', fieldId: 'paymentmethod', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'type', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'refnum', line: i}) + '</td>\n';
        xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + payamt + '</p></td>\n';
        xml += '</tr>\n';
        }
        }
        xml += '</tbody>\n';
        xml += '</table>\n';
        xml += '</body>\n</pdf>';
      return xml;
    }
  return {
    generateXml:generateXml,
    onRequest: onRequest
  }
});
我遇到的主要障碍是,我们的许多客户在他们的客户名称中都有符号and,xml将其解释为运算符,这需要在“实体”子列表字段上进行条件符号and处理。此外,xml希望返回更长的日期字段格式,其中包括时间戳,我使用变量和N/format模块将结果表单上的日期更改为mm/dd/yyyy格式

所有这些都会在您的存款屏幕上放置一个自定义按钮,标记为“打印存款单”,或者您选择在用户事件脚本中标记它的任何内容。当你点击它时,它会在一个新窗口中为你提供一个pdf表单,如下所示(请注意,出于本演示的目的,潜在的敏感信息已经被像素化):


就这样!我希望这能在将来帮助其他人。

我不能停止改进这一点。这里有一个更新的suitelet代码,它修改了我们的ampersand替换,以全局替换实体名称中的所有ampersand实例(是的,我们有一个客户有两个ampersand)

此外,我还添加了for循环,以显示来自“其他存款”子列表的数据,以及当数据存在于这些子列表中的任何一个或两个中时的“现金返还”

define(['N/render', 'N/record', 'N/xml', 'N/format'],
function(render, record, xml, format) {
/**
    *@NApiVersion 2.x
    * @NScriptType Suitelet
    * @appliedtorecord deposit
    */
/**
    * <code>onRequest</code> event handler
    * @gov 0
    * 
    * @param request
    *           {Object}
    * @param response
    *           {String}
    * 
    * @return {void}
    * 
    * @static
    * @function onRequest
    * @function generateXml
    */
function onRequest(context) {
    var id = context.request.parameters.custom_id;
    if (!id) {
        context.response.write('The parameter "custom_id" is required');
        return;
    }
    var xmlString = generateXml(id);
    context.response.renderPdf({ xmlString : xmlString });
}
function generateXml(id) {
      var depositRecord = record.load({ type: record.Type.DEPOSIT, id: id });
      var totes = depositRecord.getValue('total');
      var totally = format.format({value:totes, type:format.Type.CURRENCY});
      var fulldate = depositRecord.getValue('trandate');
      var mmdddate = format.format({value:fulldate, type:format.Type.DATE});
      var xml='<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">\n<pdf>\n<head>\n<macrolist>\n<macro id="nlheader">\n';
        xml += '<table width="100%" align="center" style="font-size:11px;">\n';
        xml += '<tr>\n';
        xml += '<td><b>Deposit Number:</b> ' + depositRecord.getValue('tranid') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Date:</b> ' + mmdddate + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Account:</b> ' + depositRecord.getText('account') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Total:</b> ' + totally + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Posting Period:</b> ' + depositRecord.getText('postingperiod') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Memo:</b> ' + depositRecord.getText('memo') + '</td>\n';
        xml += '</tr>\n';
        xml += '</table>\n';
        xml += '</macro>\n<macro id="nlfooter">\n<table style="width: 100%;">\n<tr>\n<td align="right" style="padding: 0; font-size:8pt;">\n<p align="right" text-align="right" ><br /><pagenumber/> of <totalpages/></p>\n</td>\n</tr>\n</table>\n</macro>\n</macrolist>\n</head>\n<body header="nlheader" header-height="13%" footer="nlfooter" footer-height="10pt" padding="0.375in 0.5in 0.5in 0.5in"  style="font:10px arial, sans-serif; text-align:left;">\n';
        xml += '<table width="100%" align="center" cellpadding="4" cellspacing="0" style="text-align:left; border-left:1px solid #ccc; border-right:1px solid #ccc;">\n';
        xml += '<thead>\n';
        xml += '<tr style="border:1px solid #ccc; background-color:#efefef;">\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Date</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>ID</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Customer</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Payment Method</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Type</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Ref No.</b></th>\n';
        xml += '<th><b>Amount</b></th>\n';
        xml += '</tr>\n';
        xml += '</thead>\n';
        xml += '<tbody>\n';
  for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'payment'})); i++)
        {
        var amt = depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'paymentamount', line: i});
        var payamt = format.format({value:amt, type:format.Type.CURRENCY});
        var longdate = depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docdate', line: i});
        var shortdate = format.format({value:longdate, type:format.Type.DATE});
        if (depositRecord.getSublistText({sublistId: 'payment', fieldId: 'deposit', line: i}) == 'T')
        {
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' + shortdate  + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docnumber', line: i}) + '</td>\n';
        var name= depositRecord.getSublistText({sublistId: 'payment', fieldId: 'entity', line: i})
        var andName = name.match('&')
        if(andName)
            name = name.replace(/&/g, "&amp;");
        xml += '<td style="border-right:1px solid #ccc;">' + name + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistText({sublistId: 'payment', fieldId: 'paymentmethod', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'type', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'refnum', line: i}) + '</td>\n';
       xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + payamt + '</p></td>\n';
        xml += '</tr>\n';
        }
        }
  for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'other'})); i++)
        {
        var amt2 = depositRecord.getSublistValue({sublistId: 'other', fieldId: 'amount', line: i});
        var payamt2 = format.format({value:amt2, type:format.Type.CURRENCY});
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        var name2= depositRecord.getSublistText({sublistId: 'other', fieldId: 'entity', line: i})
        var andName2 = name2.match('&')
        if(andName2)
            name2 = name2.replace(/&/g, "&amp;");
        xml += '<td style="border-right:1px solid #ccc;">' + name2 + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistText({sublistId: 'other', fieldId: 'paymentmethod', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'other', fieldId: 'class', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'other', fieldId: 'refnum', line: i}) + '</td>\n';
       xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + payamt2 + '</p></td>\n';
        xml += '</tr>\n';
        }
  for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'cashback'})); i++)
        {
        var amt3 = depositRecord.getSublistValue({sublistId: 'cashback', fieldId: 'amount', line: i});
        var payamt3 = format.format({value:amt3, type:format.Type.CURRENCY});
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        var name3= depositRecord.getSublistText({sublistId: 'cashback', fieldId: 'account', line: i})
        var andName3 = name3.match('&')
        if(andName3)
            name3 = name3.replace(/&/g, "&amp;");
        xml += '<td style="border-right:1px solid #ccc;">' + name3 + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + '</td>\n';
        xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + '(' + payamt3 + ')' + '</p></td>\n';
        xml += '</tr>\n';
        }
        xml += '</tbody>\n';
        xml += '</table>\n';
        xml += '</body>\n</pdf>';
      return xml;
    }
  return {
    generateXml:generateXml,
    onRequest: onRequest
  }
});

这在我的错误控制台中给了我以下消息:UncaughtTypeError:无法读取未定义的at对象的属性“newRecord”。OnButton单击是否知道我做错了什么?如果需要,这里有一个。很抱歉代码中有错误,请尝试更新的客户端脚本
define(['N/render', 'N/record', 'N/xml', 'N/format'],
function(render, record, xml, format) {
/**
    *@NApiVersion 2.x
    * @NScriptType Suitelet
    * @appliedtorecord deposit
    */
/**
    * <code>onRequest</code> event handler
    * @gov 0
    * 
    * @param request
    *           {Object}
    * @param response
    *           {String}
    * 
    * @return {void}
    * 
    * @static
    * @function onRequest
    * @function generateXml
    */
function onRequest(context) {
    var id = context.request.parameters.custom_id;
    if (!id) {
        context.response.write('The parameter "custom_id" is required');
        return;
    }
    var xmlString = generateXml(id);
    context.response.renderPdf({ xmlString : xmlString });
}
function generateXml(id) {
      var depositRecord = record.load({ type: record.Type.DEPOSIT, id: id });
      var totes = depositRecord.getValue('total');
      var totally = format.format({value:totes, type:format.Type.CURRENCY});
      var fulldate = depositRecord.getValue('trandate');
      var mmdddate = format.format({value:fulldate, type:format.Type.DATE});
      var xml='<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">\n<pdf>\n<head>\n<macrolist>\n<macro id="nlheader">\n';
        xml += '<table width="100%" align="center" style="font-size:11px;">\n';
        xml += '<tr>\n';
        xml += '<td><b>Deposit Number:</b> ' + depositRecord.getValue('tranid') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Date:</b> ' + mmdddate + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Account:</b> ' + depositRecord.getText('account') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Total:</b> ' + totally + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Posting Period:</b> ' + depositRecord.getText('postingperiod') + '</td>\n';
        xml += '</tr>\n';
        xml += '<tr>\n';
        xml += '<td><b>Memo:</b> ' + depositRecord.getText('memo') + '</td>\n';
        xml += '</tr>\n';
        xml += '</table>\n';
        xml += '</macro>\n<macro id="nlfooter">\n<table style="width: 100%;">\n<tr>\n<td align="right" style="padding: 0; font-size:8pt;">\n<p align="right" text-align="right" ><br /><pagenumber/> of <totalpages/></p>\n</td>\n</tr>\n</table>\n</macro>\n</macrolist>\n</head>\n<body header="nlheader" header-height="13%" footer="nlfooter" footer-height="10pt" padding="0.375in 0.5in 0.5in 0.5in"  style="font:10px arial, sans-serif; text-align:left;">\n';
        xml += '<table width="100%" align="center" cellpadding="4" cellspacing="0" style="text-align:left; border-left:1px solid #ccc; border-right:1px solid #ccc;">\n';
        xml += '<thead>\n';
        xml += '<tr style="border:1px solid #ccc; background-color:#efefef;">\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Date</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>ID</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Customer</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Payment Method</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Type</b></th>\n';
        xml += '<th style="border-right:1px solid #ccc;"><b>Ref No.</b></th>\n';
        xml += '<th><b>Amount</b></th>\n';
        xml += '</tr>\n';
        xml += '</thead>\n';
        xml += '<tbody>\n';
  for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'payment'})); i++)
        {
        var amt = depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'paymentamount', line: i});
        var payamt = format.format({value:amt, type:format.Type.CURRENCY});
        var longdate = depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docdate', line: i});
        var shortdate = format.format({value:longdate, type:format.Type.DATE});
        if (depositRecord.getSublistText({sublistId: 'payment', fieldId: 'deposit', line: i}) == 'T')
        {
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' + shortdate  + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'docnumber', line: i}) + '</td>\n';
        var name= depositRecord.getSublistText({sublistId: 'payment', fieldId: 'entity', line: i})
        var andName = name.match('&')
        if(andName)
            name = name.replace(/&/g, "&amp;");
        xml += '<td style="border-right:1px solid #ccc;">' + name + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistText({sublistId: 'payment', fieldId: 'paymentmethod', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'type', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'payment', fieldId: 'refnum', line: i}) + '</td>\n';
       xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + payamt + '</p></td>\n';
        xml += '</tr>\n';
        }
        }
  for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'other'})); i++)
        {
        var amt2 = depositRecord.getSublistValue({sublistId: 'other', fieldId: 'amount', line: i});
        var payamt2 = format.format({value:amt2, type:format.Type.CURRENCY});
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        var name2= depositRecord.getSublistText({sublistId: 'other', fieldId: 'entity', line: i})
        var andName2 = name2.match('&')
        if(andName2)
            name2 = name2.replace(/&/g, "&amp;");
        xml += '<td style="border-right:1px solid #ccc;">' + name2 + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistText({sublistId: 'other', fieldId: 'paymentmethod', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'other', fieldId: 'class', line: i}) + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + depositRecord.getSublistValue({sublistId: 'other', fieldId: 'refnum', line: i}) + '</td>\n';
       xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + payamt2 + '</p></td>\n';
        xml += '</tr>\n';
        }
  for (var i = 0; i < parseInt(depositRecord.getLineCount({sublistId: 'cashback'})); i++)
        {
        var amt3 = depositRecord.getSublistValue({sublistId: 'cashback', fieldId: 'amount', line: i});
        var payamt3 = format.format({value:amt3, type:format.Type.CURRENCY});
        xml += '<tr style="border-bottom:1px solid #ccc;">\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' +  '</td>\n';
        var name3= depositRecord.getSublistText({sublistId: 'cashback', fieldId: 'account', line: i})
        var andName3 = name3.match('&')
        if(andName3)
            name3 = name3.replace(/&/g, "&amp;");
        xml += '<td style="border-right:1px solid #ccc;">' + name3 + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + '</td>\n';
        xml += '<td style="border-right:1px solid #ccc;">' + '</td>\n';
        xml += '<td align="right" style="text-align:right !important;"><p style="text-align:right !important;">' + '(' + payamt3 + ')' + '</p></td>\n';
        xml += '</tr>\n';
        }
        xml += '</tbody>\n';
        xml += '</table>\n';
        xml += '</body>\n</pdf>';
      return xml;
    }
  return {
    generateXml:generateXml,
    onRequest: onRequest
  }
});