STC Custom Advance PDF Documents

Apps Details
To show data that is not available on the record, a common approach is to create a button which then calls a Suitelet. This Suitelet uses saved searches or queries to generate the data needed on the Advanced PDF and then renders the PDF. This is fine but what if there was a way to natively print the PDF without the need for a custom button?

Solution

Create a User Event Script on the record. In the beforeLoad function get the data you need using Saved Searches or SuiteQL. Create a custom field to store the data.
				
					/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 * @NModuleScope Public
 *
 */


define([
    'N/record',
    'N/search',
    'N/ui/serverWidget'
]
,  (
    record,
    search,
    serverWidget
) => {
        beforeLoad = (context) => {
			if (context.type == context.UserEventType.PRINT) {
				const newRecord = context.newRecord;
				// Create the custom field to save data
				let dataForPDF = context.form.addField({
					id: 'custpage_data_for_pdf',
					type: serverWidget.FieldType.LONGTEXT,
					label: 'data for pdf'
				});
				dataForPDF.updateDisplayType({ displayType: serverWidget.FieldDisplayType.HIDDEN });

				// Call Search function(s) to get all the data you need.  This should return an object
				let dataObject = getData();
				dataForPDF.defaultValue = JSON.stringify(dataObject);
			}
        }

		getData = () => {
			// get all the data using searches or SuiteQL
			return dataObject;
		}


		return {
            beforeLoad: beforeLoad
        };
});
				
			
In the Advanced PDF reference the generated field. Use “eval” to parse the data into an object.
				
					<#assign data = record.custpage_data_for_pdf?eval> <p> ${data.field}</p>
				
			

Conclusion

This simple solution allows you reach data you otherwise would not be able to on an advanced PDF.  It does this without the need for a custom button.

Do you need help with customizing NetSuite?  Suite Tooth Consulting specializes in all sorts of customization for NetSuite including scripting, workflows, advanced PDFs, and integrations.  Get a free consultation.

If you liked this article, please sign up for my newsletter to get these delivered to your inbox here.

Your Guide To Understanding Us Better