Render advanced PDF using NetSuite data from any record

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.

Follow on
Jaime Requena Chief Executive Officer

Jaime Requena is a seasoned NetSuite Consultant and Solutions Architect, known for delivering WHITE GLOVE service to businesses. With 15+ years of experience and 3x certifications in ERP, Developer, and Admin, Jaime specializes in highly customized NetSuite accounts, transforming operations for 200+ satisfied customers all across the globe.

Get Connected

How can we help?


    Stay in the loop with Suite Tooth Consulting!

    We aim to bring unmatched expertise and professionalism to your NetSuite initiatives. Let’s talk about how our NetSuite consultancy can make a difference!

    Global Client Satisfaction

    Client Testimonials

    It’s Been 4+ Years Now And We Have Worked With Hundreds Of Clients, Building Our Way To The Top, One Happy Client After Another! Their Voices Of Satisfaction Serve As A Testament To Our Success –