I'm a non-developer who's brand new to NetSuite and SuiteScript and I'm stumbling my way through.
The problem: For each deposit record I need to create a printable pdf which lists each of the payments on that record (a Bank Deposit Slip). I would like to call this pdf on a custom button to display in a new window that I can print from. I do not need to save the document in the file cabinet.
1. Right now I have a UserEvent button that shows up on Deposits in view and edit modes.
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. This button calls a clickhandler function "onButtonClick" from a ClientScript named "customDepositSlipButton.js"
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;
});
Currently this works, but only creates a dialog popup for testing purposes. So far, so good. testing popup
And here's where I'm stuck: I don't understand how to now connect this to a function on a Suitelet which should generate a pdf file from xml.
3. I've set up a Suitelet with a pdf from xml script in that same file cabinet location titled "depositSlipPDF.js" with the function "generatePdfFileFromRawXml" as follows.
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
}
});
How do I call generatePdfFileFromRawXml(); from onButtonClick();?
Credit for getting this far goes to Stoic Software where SS2 is made understandable (thank you, Eric) and to teamtag for this post where I'm getting the code for these initial xml data pulls.