Advanced PDF Template via a Button

My company was getting requests for credit references for some of our customers. This was a time-consuming process to format our customized response. As our NetSuite developer, I was asked to automate a custom PDF that would get emailed back to the requestor. Our staff wanted it to be easily launched from a button on the customer’s record.

I wanted to use an Advanced PDF/HTML Template to create the PDF. NetSuite supports the using advanced templates on saved search results, but there is no mechanism for launching this via a button on a customer record. And in order to get the result for just one customer, it’s another multi-step process which involved opening the Saved Search, filtering and then printing. Not acceptable!

Here are the steps I followed to build a PDFed credit reference launched from a button on a customer’s record.

1. Create a Saved Search that lets you filter to show results for just one customer. 

1b. Limit your results to just one and don’t allow drill down.

Search Results Limit to One

2. After saving this search, click the “New Template” button at the top of the page. This step is well documented in the NetSuite documentation. Be sure you code your template so that you are processing summary results. You’ll see what I mean if you read SuiteAnswers Answer ID # 63077. <#list results as result> is where you get your summary results.

PDF Template with Results

3. Since the Saved Search returns only one customer, you can code your advanced template to access fields like this. 

Field References

4. It’s easy to add buttons when editing a customer. However, not so easy when you’re viewing the customer. Here’s how I did that. 

Events Script

5. Finally, you need the client script that accepts the btnCreditCheck_Click() call. In my case, “customscript_logic_client_customers_view” contains the Javascript which opens my new Advanced PDF/HTML Template and filters on Internal ID. When you upload your client script, you need to define it as type = “Client”. However, it does not need any methods (in the definition) and it does not need to be deployed! You’ll need the script ID for line 14 above.

Client Script

In order to get the URL of my Advanced PDF/HTML Template, I had to run my query and then select a customer and print the results.

Printing the Saved Search

This exposed my template’s URL. I had to remove the hard-coded Internal ID of the customer and replace it. The event script passes it to the client script, which adds it to the URL as a query string parameter.

Here how this looked when it was all done. First, the new button.

Credit Check Button

And then the PDF that opens in its own window when you click the button.

Printed Template

I hope this saves you some time. If nothing else, it will save me some time the next I need to do something like this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s