Back to Blogs
NetSuite Diaries

Manual Email Sending via NetSuite: PDF Details Not Rendering Due to User-Event Limitations

Vanessa Sampang
September 4, 2024
3
minutes to read

Handling Advanced HTML/PDFs in NetSuite can be challenging, especially when dealing with complex data not directly available on a record. This article explores a specific scenario, highlights the challenges, including the limitations imposed by user events, and walks through the solution implemented to enhance efficiency.

Scenario: Complex Template Needs

The company needed to improve its efficiency in sending emails to customers while retaining the ability to include PDFs as attachments using the Email Mail Merge interface. The challenge was that the PDF template required details from various datasets that were not directly accessible at the record level.

Existing Solution

The company’s existing solution involved using a user-event script deployed on the beforeLoad event of a transaction. This script was designed to pull the necessary data from various records using SQL or a Saved Search. The gathered data was then stored in a custom scripted field, which was subsequently referenced in the template to generate the PDF document. This method effectively consolidated all the required data for a comprehensive output.

<#assign data = record.custpage_forklift_history>
<#if data?has_content>
<#assign data = data?eval>
   <table width = "100%">
       <#list data as item>
       <#if item_index==0>
           <thead>
               <tr>
                   <th align="center">Date</th>
                   <th align="center">Notes</th>
               </tr>
           </thead>
       </#if>
       <tr>
           <td align="center">${item.date}</td>
           <td align="center">${item.message}</td>
       </tr>
       </#list>
   </table>
</#if>

Initially, this method worked well for generating PDFs when printing directly through the User Interface or when performing bulk printing. However, issues emerged when attempting to use NetSuite's native Mail Merge functionality.

Problem: Email Challenges

The issue appeared when using NetSuite's built-in email feature to send these PDF attachments to customers. The user-event script that renders the data didn’t trigger during the mail merge process, resulting in PDFs that were often incomplete or missing information.

Workaround: Manual Attachments

As a workaround, users manually print the PDF from the transaction form and then attach them to email messages. While this manual process ensured that all data was present, it wasn’t practical or efficient for long-term use.

Solution: On Demand Attachment

To eliminate the manual process and ensure complete and accurate PDFs in email communications, the team implemented a more streamlined approach.

1. User-Event Script on Message Record

Instead of relying on manual download and attachment, a user-event script was deployed on the Message Record. A scripted field called “Include PDF” was created, and a client script was added to trigger a Suitelet for generating the PDF. The native field was hidden to prevent unnecessary attachments generated by the system.

2. Suitelet to Generate PDF

The Suitelet was created to generate the PDF using render.transaction(). This then triggered the user event responsible for gathering the necessary dataset. By calling this Suitelet, the beforeLoad event of the transaction was triggered properly, ensuring that data from all sources was included in the generated PDF.

3. Managing Attachments

After generating the PDF, the Suitelet returned the internal ID of the newly created PDF. This ID was then used to automatically attach the PDF to the email message's Attachment sublist, ensuring a seamless process.

Result

By automating the PDF generation and attachment process, emails now include complete and accurate PDFs without any manual steps. This solution not only saved time but also reduced the chances of errors and ensured a more reliable email process.

before-and-after
email-message-attachment

Curious About Your Take

Addressing user-event limitations in NetSuite can be challenging. I'm curious – how would you approach this issue? We'd love to hear your thoughts!

Meet the Author

vanessa-sampang-author

With over a decade of hands-on experience in NetSuite development, Vanessa has worked with global NetSuite partners and end-users, specializing in implementation, integration, administration, and support. She has also mentored fellow NetSuite developers during her consulting career. In 2015, Vanessa co-founded CloudCompass Technologies, an independent NetSuite practice focusing on managed services.