NetSuite SuiteScript 2.0 如何从 UserEvent 按钮创建银行存款单(suitelet 函数)
NetSuite SuiteScript 2.0 How do I create a Bank Deposit Slip (suitelet function) from a UserEvent Button
我 non-developer 是 NetSuite 和 SuiteScript 的新手,我正在跌跌撞撞地学习。
问题: 对于每个存款记录,我需要创建一个可打印的 pdf 文件,其中列出该记录上的每笔付款(银行存款单)。我想在自定义按钮上调用此 pdf 以显示在我可以打印的新 window 中。我不需要将文档保存在文件柜中。
1. 现在我有一个 UserEvent 按钮,它在查看和编辑模式下显示在存款上。
define([], function () {
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
var exports = {};
function beforeLoad(context) {
context.form.addButton({
id: "custpage_printdepositslip",
label: "Print Deposit Slip",
functionName: "onButtonClick"
});
context.form.clientScriptModulePath = "SuiteScripts/depositSlips/customDepositSlipButton.js"
}
exports.beforeLoad = beforeLoad;
return exports;
});
2. 此按钮从名为 "customDepositSlipButton.js"
的 ClientScript 调用点击处理函数 "onButtonClick"
define(["N/ui/dialog"], function (dialog) {
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
var exports = {};
function pageInit(context) {
// TODO
}
function onButtonClick() {
dialog.alert({
title: "COMING SOON",
message: "This feature will eventually create a bank deposit slip"
});
}
exports.onButtonClick = onButtonClick;
exports.pageInit = pageInit;
return exports;
});
目前这可行,但仅为测试目的创建一个对话框弹出窗口。到目前为止,一切都很好。
testing popup
这就是我卡住的地方: 我现在不明白如何将它连接到 Suitelet 上的一个函数,它应该从 xml.
3. 我在标题为 "depositSlipPDF.js" 的同一个文件柜位置设置了一个带有来自 xml 脚本的 pdf 的 Suitelet,函数为 "generatePdfFileFromRawXml"如下。
define(['N/render', 'N/record'],
function(render, record) {
/**
* @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 generatePdfFileFromRawXml() {
var xml = '<?xml version="1.0"?>n<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">n<pdf>n<body size="letter-landscape" font-size="10">n';
xml += '<table width="100%" align="center">n';
xml += '<tr>n';
xml += '<td>Deposit Number: ' + depositRecord.getFieldValue('tranid') + '</td>n';
xml += '</tr>n';
xml += '<tr>n';
xml += '<td>Date: ' + depositRecord.getFieldValue('trandate') + '</td>n';
xml += '</tr>n';
xml += '<tr>n';
xml += '<td>Total: ' + depositRecord.getFieldValue('total') + '</td>n';
xml += '</tr>n';
xml += '<tr>n';
xml += '<td>Posting Period: ' + depositRecord.getFieldText('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 = 1; i < parseInt(depositRecord.getLineItemCount('payment')) + 1; i++)
{
if (depositRecord.getLineItemValue('payment', 'deposit', i) == 'T')
{
xml += '<tr>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'docdate', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'docnumber', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemText('payment', 'entity', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'paymentamount', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'transactionamount', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'type', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemText('payment', 'paymentmethod', i) + '</td>n';
xml += '</tr>n';
}
}
xml += '</tbody>n';
xml += '</table>n';
xml += '</body>n</pdf>';
var pdfFile = render.xmlToPdf({
xmlString: xmlStr
});
}
return {
onRequest: generatePdfFileFromRawXml
}
});
如何调用 generatePdfFileFromRawXml();来自 onButtonClick();?
走到这一步要归功于 Stoic Software where SS2 is made understandable (thank you, Eric) and to teamtag for this post,我在那里获取这些初始 xml 数据拉取的代码。
您的 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
模块):
function onButtonClick() {
var suiteletUrl = url.resolveScript({
scriptId: 'customscript_printdepositslip', // replace with correct script id
deploymentId: 'customdeploy_printdepositslip', // replace with correct deployment id
returnExternalUrl: false,
params: {
custom_id: currentRecord.get().id,
},
});
window.open(suiteletUrl);
}
免责声明:以上代码未经测试,可能包含语法错误!
我也在尝试同样的事情。我的终于可以用了,尝试将 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>';
看看是否可以修复您的解析 XML 错误。
使用前面两个答案的输入,这里是完整的工作解决方案和结果的屏幕截图:
步骤 1) 为自定义按钮建立 click-handler 的客户端脚本,这会获取我当前记录的 ID 并将其传递给我的 suitelet,后者在新的 window[=14 中执行=]
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) 用户事件脚本创建一个在我的存款记录的编辑和查看模式下可见的自定义按钮,并从我的客户端脚本调用 click-handler。
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 脚本从 xml 相对于当前存款的记录 ID(您单击按钮的位置)创建自定义表单,它从存款子列表和 return 以 pdf 格式组织 table,如果 table 需要多个页面,则页眉和页脚部分会保留在每一页上。
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("&", "&");
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
}
});
我 运行 遇到的主要障碍是我们的许多客户的客户名称中都有 & 符号,xml 将其解释为运算符,这需要对 "实体”子列表字段。此外,xml 想要 return 包含时间戳的更长形式的日期字段,我正在使用变量和 N/format 模块将日期更改为 mm/dd/yyyy 在生成的表单上设置格式。
所有这一切都会在您的存款屏幕上放置一个自定义按钮,标记为“打印存款单”或您在用户事件脚本中选择标记的任何内容。当你点击它时,它应该会在一个新的 window 中给你一个 pdf 表格,看起来像这样(请注意,为了这个演示的目的,潜在的敏感信息已经被像素化):
就是这样!我希望这对以后的其他人有所帮助。
我无法停止改进它。这是一个更新的 suitelet 代码,它修改了我们的 & 符号替换以全局替换实体名称中的所有 & 符号实例(是的,我们有一个客户有两个 & 符号)。
此外,我添加了 for 循环以显示来自 "Other Deposits" 子列表的数据以及 "Cash Back" 当数据存在于这些子列表中的一个或两个中时。
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, "&");
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, "&");
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, "&");
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
}
});
我 non-developer 是 NetSuite 和 SuiteScript 的新手,我正在跌跌撞撞地学习。
问题: 对于每个存款记录,我需要创建一个可打印的 pdf 文件,其中列出该记录上的每笔付款(银行存款单)。我想在自定义按钮上调用此 pdf 以显示在我可以打印的新 window 中。我不需要将文档保存在文件柜中。
1. 现在我有一个 UserEvent 按钮,它在查看和编辑模式下显示在存款上。
define([], function () {
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
var exports = {};
function beforeLoad(context) {
context.form.addButton({
id: "custpage_printdepositslip",
label: "Print Deposit Slip",
functionName: "onButtonClick"
});
context.form.clientScriptModulePath = "SuiteScripts/depositSlips/customDepositSlipButton.js"
}
exports.beforeLoad = beforeLoad;
return exports;
});
2. 此按钮从名为 "customDepositSlipButton.js"
的 ClientScript 调用点击处理函数 "onButtonClick"define(["N/ui/dialog"], function (dialog) {
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
var exports = {};
function pageInit(context) {
// TODO
}
function onButtonClick() {
dialog.alert({
title: "COMING SOON",
message: "This feature will eventually create a bank deposit slip"
});
}
exports.onButtonClick = onButtonClick;
exports.pageInit = pageInit;
return exports;
});
目前这可行,但仅为测试目的创建一个对话框弹出窗口。到目前为止,一切都很好。 testing popup
这就是我卡住的地方: 我现在不明白如何将它连接到 Suitelet 上的一个函数,它应该从 xml.
3. 我在标题为 "depositSlipPDF.js" 的同一个文件柜位置设置了一个带有来自 xml 脚本的 pdf 的 Suitelet,函数为 "generatePdfFileFromRawXml"如下。
define(['N/render', 'N/record'],
function(render, record) {
/**
* @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 generatePdfFileFromRawXml() {
var xml = '<?xml version="1.0"?>n<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">n<pdf>n<body size="letter-landscape" font-size="10">n';
xml += '<table width="100%" align="center">n';
xml += '<tr>n';
xml += '<td>Deposit Number: ' + depositRecord.getFieldValue('tranid') + '</td>n';
xml += '</tr>n';
xml += '<tr>n';
xml += '<td>Date: ' + depositRecord.getFieldValue('trandate') + '</td>n';
xml += '</tr>n';
xml += '<tr>n';
xml += '<td>Total: ' + depositRecord.getFieldValue('total') + '</td>n';
xml += '</tr>n';
xml += '<tr>n';
xml += '<td>Posting Period: ' + depositRecord.getFieldText('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 = 1; i < parseInt(depositRecord.getLineItemCount('payment')) + 1; i++)
{
if (depositRecord.getLineItemValue('payment', 'deposit', i) == 'T')
{
xml += '<tr>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'docdate', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'docnumber', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemText('payment', 'entity', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'paymentamount', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'transactionamount', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemValue('payment', 'type', i) + '</td>n';
xml += '<td>' + depositRecord.getLineItemText('payment', 'paymentmethod', i) + '</td>n';
xml += '</tr>n';
}
}
xml += '</tbody>n';
xml += '</table>n';
xml += '</body>n</pdf>';
var pdfFile = render.xmlToPdf({
xmlString: xmlStr
});
}
return {
onRequest: generatePdfFileFromRawXml
}
});
如何调用 generatePdfFileFromRawXml();来自 onButtonClick();?
走到这一步要归功于 Stoic Software where SS2 is made understandable (thank you, Eric) and to teamtag for this post,我在那里获取这些初始 xml 数据拉取的代码。
您的 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
模块):
function onButtonClick() {
var suiteletUrl = url.resolveScript({
scriptId: 'customscript_printdepositslip', // replace with correct script id
deploymentId: 'customdeploy_printdepositslip', // replace with correct deployment id
returnExternalUrl: false,
params: {
custom_id: currentRecord.get().id,
},
});
window.open(suiteletUrl);
}
免责声明:以上代码未经测试,可能包含语法错误!
我也在尝试同样的事情。我的终于可以用了,尝试将 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>';
看看是否可以修复您的解析 XML 错误。
使用前面两个答案的输入,这里是完整的工作解决方案和结果的屏幕截图:
步骤 1) 为自定义按钮建立 click-handler 的客户端脚本,这会获取我当前记录的 ID 并将其传递给我的 suitelet,后者在新的 window[=14 中执行=]
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) 用户事件脚本创建一个在我的存款记录的编辑和查看模式下可见的自定义按钮,并从我的客户端脚本调用 click-handler。
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 脚本从 xml 相对于当前存款的记录 ID(您单击按钮的位置)创建自定义表单,它从存款子列表和 return 以 pdf 格式组织 table,如果 table 需要多个页面,则页眉和页脚部分会保留在每一页上。
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("&", "&");
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
}
});
我 运行 遇到的主要障碍是我们的许多客户的客户名称中都有 & 符号,xml 将其解释为运算符,这需要对 "实体”子列表字段。此外,xml 想要 return 包含时间戳的更长形式的日期字段,我正在使用变量和 N/format 模块将日期更改为 mm/dd/yyyy 在生成的表单上设置格式。
所有这一切都会在您的存款屏幕上放置一个自定义按钮,标记为“打印存款单”或您在用户事件脚本中选择标记的任何内容。当你点击它时,它应该会在一个新的 window 中给你一个 pdf 表格,看起来像这样(请注意,为了这个演示的目的,潜在的敏感信息已经被像素化):
就是这样!我希望这对以后的其他人有所帮助。
我无法停止改进它。这是一个更新的 suitelet 代码,它修改了我们的 & 符号替换以全局替换实体名称中的所有 & 符号实例(是的,我们有一个客户有两个 & 符号)。
此外,我添加了 for 循环以显示来自 "Other Deposits" 子列表的数据以及 "Cash Back" 当数据存在于这些子列表中的一个或两个中时。
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, "&");
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, "&");
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, "&");
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
}
});