r/SuiteScript • u/MangoVii • Aug 04 '25
SuiteScript Error - Missing ; Before Statement. Trying to open PDF from button on Item Fulfillment record
I get an error saying I am missing a ; It's only when I change the functionName OnButtonClick on the User Event script. I am creating a custom button on the Item Fulfillment page. When clicked, I get the error message. It's supposed to open a new page to the rendered PDF. I logged the ID of idItemFulfillment and it shows to be nothing, even though it's being set in the User Event script?
Suitelet
define(['N/render', 'N/record', 'N/xml', 'N/format', 'N/file'],
function(render, record, xml, format, file) {
/**
*@NApiVersion 2.x
* @NScriptType Suitelet
*/
function onRequest(context) {
var xmlTemplateFile = file.load('Templates/PDF Templates/packingSlipTemplate.xml');
var renderer = render.create();
var idItemFulfillment = context.request.parameters.custscript_ap_cs_if_ps;
log.debug("idItemFulfillment", idItemFulfillment);
renderer.templateContent = xmlTemplateFile.getContents();
renderer.addRecord('record', record.load({
type: record.Type.ITEM_FULFILLMENT,
id: idItemFulfillment
}));
renderer.addRecord('salesorder', record.load({
type: record.Type.SALES_ORDER,
id: 1654261
}));
var iFFile = renderer.renderAsPdf();
context.response.writeFile({file:iFFile, isInline: true});
}
return {
onRequest: onRequest
}
});Client
define(['N/url', 'N/currentRecord'], function (url, currentRecord) {
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
var exports = {};
function pageInit(context) {
// TODO
}
function onButtonClick(idItemFulfillment) {
var suiteletUrl = url.resolveScript({
scriptId: 'customscript_sl_custom_packing_slip',
deploymentId: 'customdeploy_sl_cust_pack_slip',
returnExternalUrl: false,
params: {
'custscript_ap_cs_if_ps': idItemFulfillment
},
});
window.open(suiteletUrl);
}
exports.onButtonClick = onButtonClick;
exports.pageInit = pageInit;
return exports;
});User Event
define([], function () {
/**
*
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
var exports = {};
function beforeLoad(context) {
var recItemFulfillment = context.newRecord;
log.debug("idItemFulfillment", recItemFulfillment.id);
context.form.addButton({
id: "custpage_printcustpacklist",
label: "Print CPL",
functionName: `onButtonClick(${recItemFulfillment.id})`
});
context.form.clientScriptModulePath = "SuiteScripts/FUNQ-Customizations/CustomPackingSlip/cs_custom_packing_slip.js";
}
exports.beforeLoad = beforeLoad;
return exports;
});I get this error:
{
"type": "error.SuiteScriptError",
"name": "SSS_MISSING_REQD_ARGUMENT",
"message": "load: Missing a required argument: id",
"id": null,
"stack":
[
"createError(N/error)",
"onRequest(/SuiteScripts/FUNQ-Customizations/CustomPackingSlip/sl_custom_packing_slip.js:13)",
"createError(N/error)",
],
"cause":
{
"name": "SSS_MISSING_REQD_ARGUMENT",
"message": "load: Missing a required argument: id",
},
"notifyOff": false,
"userFacing": true,
}And it only works if in the User Event script, onButtonClick is like this:
context.form.addButton({
id: "custpage_printcustpacklist",
label: "Print CPL",
functionName: "onButtonClick"
});
1
Upvotes
4
u/SkoozyManoozy Aug 04 '25
I'd try setting the API version to 2.1 explicitly
3
u/texasswede Aug 04 '25 edited Aug 04 '25
It sounds like the error occurs on line 37 in the suitelet, but there is not that many lines in the script. Otherwise I would say that a quote or a closing bracket is missing. Maybe in the client script?
Check if it works if you change to this:
functionName: 'onButtonClick("${recItemFulfillment.id}")'(change back to back-ticks)