Requirement of the client is to print the packing slip in the invoice record. For that a custom button have to be added in the invoice record. Then pass the suitelet id in clientscript.
UserEventScript to create a custom button in the invoice record to print the packing slip.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([],
() => {
/**
* Defines the function definition that is executed before record is loaded.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @param {Form} scriptContext.form - Current form
* @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
* @since 2015.2
*/
const beforeLoad = (scriptContext) => {
try{
if(scriptContext.type === scriptContext.UserEventType.VIEW ) {
let itemFulfillemnt = scriptContext.newRecord.getValue({
fieldId: 'custbody_jj_item_fulfillment_fl_37'
});
scriptContext.form.addButton({
id: 'custpage_packing_slip_button',
label: 'Print Bunnings Packing Slip',
functionName: `printPackingSlip(${itemFulfillemnt})`
});
scriptContext.form.clientScriptModulePath = 'SuiteScripts/Jobin and Jismi IT Services LLP/Packing Slip Customization FL-34/FL-37 Print Bunnings Packing Slip/JJ CS Print Bunnings Packing Slip FL-37.js' ;
}
}catch(error){
log.error("Error @beforeLoad",error);
}
}
return {beforeLoad}
});
Clientscript to passing the script id of the suitelet
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord','N/url','N/log'],
/**
* @param{currentRecord} currentRecord
* @param{url} url
* @param{log} log
*/
function(currentRecord,url,log) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
console.log("jhgwgdkwhd");
}
/**
* function for getting itemfulfillmentid
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {currentRecord} currentRecord
*
*/
function printPackingSlip(itemFulfillment){
try {
console.log("itemfulfillment",itemFulfillment)
var createLinkUrl = url.resolveScript({
scriptId: 'customscript_jj_sl_print_packing_slip',
deploymentId: 'customdeploy_jj_sl_print_packing_slip',
returnExternalUrl: false,
params: {
itemFulfillment: itemFulfillment
}
});
console.log("createLinkUrl",createLinkUrl)
window.open(createLinkUrl)
}catch (e) {
log.debug(e)
}
}
return {
pageInit: pageInit,
printPackingSlip: printPackingSlip
};
});
Suite let to print the pdf
/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define(['N/log','N/render'],
(log,render) => {
/**
* Defines the Suitelet script trigger point.
* @param {Object} scriptContext
* @param {ServerRequest} scriptContext.request - Incoming request
* @param {ServerResponse} scriptContext.response - Suitelet response
* @since 2015.2
*/
const onRequest = (scriptContext) => {
try {
log.debug("On request","qwjfhwilfhi3");
if (scriptContext.request.method === 'GET') {
const record = scriptContext.request.parameters.itemFulfillment;
const printInvoice = render.transaction({
entityId: parseInt(record),
formId: 191,
printMode: render.PrintMode.PDF,
inCustLocale: true
});
scriptContext.response.writeFile(printInvoice,true)
}
} catch (error) {
log.error('Error @onRequest', error);
}
}
return {onRequest}
});