Maher Chamma 5min read

When NetSuite generates a transaction PDF file, the file name by default takes the id of the record rather than the transaction number. This is a major annoyance to many users and many are often so used to it that renaming the file is just part of their habit. Even though it may not take very long, the few seconds can add up over thousands of transactions.

Use the method and scripts below to work around this limitation on any transaction document in a few minutes:

 

  1. Add the suitelet below to render the PDF with your own file naming convention:

    /**
     * @NApiVersion 2.1
     * @NScriptType Suitelet
     * @since 9/5/2022
     * @author Maher Chamma
     * @description
     */

    define(['N/render', 'N/search'],
      function(render, search) {
        function onRequest(context) {
          const req = context.request;
          const params = req.parameters;
          if (req.method === 'GET') {
            const tranLup = search.lookupFields({ type: 'transaction', id: params.id, columns: ['tranid', 'type'] });
            let pdfFile = null;
            if (tranLup.type[0].value === 'WorkOrd') {
              pdfFile = render.bom({ entityId: Number(params.id) });
            } else {
              pdfFile = render.transaction({ entityId: Number(params.id) });
            }
            pdfFile.name = tranLup.tranid + '.pdf';
            return context.response.writeFile({ file: pdfFile });
          }
        }
        return {
          onRequest: onRequest
        };
      }
    );

    In the case above we just used the transaction number itself so it will output as SO1786.pdf for example. If you want to customize the file name further you can pass more columns into the lookup such as the transaction date or customer.
  2. Add the user event code to render the custom print button on your transaction record:

    /**
    *@NApiVersion 2.1
    *@NScriptType UserEventScript
    */
    define(['N/url'], function(url) {
      function beforeLoad(context) {
        if (context.type === context.UserEventType.VIEW) {
          const newRec = context.newRecord;
          try {
            const uiForm = context.form;
            const slUrl = url.resolveScript({
              scriptId: 'customscript_ea_alt_print_sl',
              deploymentId: 'customdeploy1',
              params: {
                id: newRec.id
              }
            });
            uiForm.addButton({ id: 'custpage_ea_alt_print', label: 'Print', functionName: 'window.open("' + slUrl + '","_self")' });
          } catch (err) {
            log.error('err:' + newRec.id, err);
          }
        }
      }
      return {
        beforeLoad: beforeLoad
      };
    });

In step # 2 the url.resolveScript is generating the URL to your suitelet in step 1 so be careful to lineup the script id and deployment id of the suitelet script record to match.

If you only want to have a single print option per record make sure to also remove the native Print option by customizing your form.

Hope this helps and you get back precious minutes of the day!

 

 

Maher Chamma

Principal at Entartes

Leave us a comment!


TOP POST YOU CAN BE INTERESTED

10 Key Factors in a Successful NetSuite Implementation

Entartes Content Team 5 min read

Whatever industry you operate in, deploying an enterprise resource planning system is a significant undertaking that cannot be taken lightly. ERP implementation efforts need the dedication of the ...

Read More

Add Login Audit Trail Sublist

Maher Chamma 5 min read

As a NetSuite administrator, sometimes you need to troubleshoot an employee role or permission. In other cases you may want to just view their login activity to see if it is worth assigning the ...

Read More

How to Plan and Prepare for Your NetSuite Implementation

Maher Chamma 5 min read

ERP implementations are notoriously tedious and often quite intimidating for a business just beginning the process. With most ERP systems affecting multiple departments and teams, you want to ensure ...

Read More

Be in the know!

Subscribe to our blog and access key knowledge and expertise across a host of technology platforms to fuel your business.


Subscribe