Suite Tooth Consulting
All articles
Render Advanced PDF Using Any NetSuite Record Data
NetSuite How-Tos & Tips

Render Advanced PDF Using Any NetSuite Record Data

1 min read

Push past Advanced PDF field limits in NetSuite. Render PDFs with data sourced from any record, search, or related transaction.

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>
 
${data.field}

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.