I have created a print pfd button on my project record. The intention is build a pdf project summary to send to clients. When I click the button I get a Suite Script Error.
This is my error.
EVENTSCRIPT
define([],function () {
var exports = {};
function beforeLoad(context) {
context.form.addButton({
id: "custpage_mybutton",
label: "Print Project Summary",
functionName: "onButtonClick"
});
context.form.clientScriptModulePath = "SuiteScripts/job_cs_test_message.js"
}
exports.beforeLoad = beforeLoad;
return exports;
});
CLIENTSCRIPT
define(["N/url", "N/currentRecord"], function(url, currentRecord) {
var exports = {};
function pageInit(context) {
// TODO
}
function onButtonClick() {
var suiteletUrl = url.resolveScript({
scriptId: 'customscript_job_su_printpdf',
deploymentId: 'customdeploy_job_su_printpdf',
returnExternalUrl: false,
params: {
custom_id: currentRecord.get().id,
},
});
window.open(suiteletUrl);
}
exports.onButtonClick = onButtonClick;
exports.pageInit = pageInit;
return exports;
});
SUITELET
define(['N/render', 'N/file', 'N/record'],
function(render, file, record)
{
function onRequest(context) {
function renderRecordToPdfWithTemplate() {
var custom_id = context.request.parameters.custom_id;
var xmlTemplateFile = file.load('Templates/PDF Templates/custtmpl_job_pdf_test.xml');
var renderer = render.create();
renderer.templateContent = xmlTemplateFile.getContents();
renderer.addRecord('record', record.load({
type: record.Type.JOB,
id: custom_id
}));
var invoicePdf = renderer.renderAsPdf();
}
renderRecordToPdfWithTemplate();
}
return {
onRequest: onRequest
}
});
XML
<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
<meta name="title" value="My First Document"/>
</head>
<body background-color="yellow" font-size="18">
Hello, World!
</body>
</pdf>
I have tried many variations, focusing mainly on the addRecord command. I did this because it initially worked in the employee record, so I was working on the assumption it was the move to a project record that caused this issue.
That being said, I recently found a related topic which I think holds the real answer. However, it was not updated by the person who asked the questions.
It suggests only passing the ID and not the whole context. I'll be honest, I didn't really know what that meant.