skip to Main Content

I’m trying to call a script with a button that I created on specific file type. It originally called a client script but I realized the render module is for server scripts only. I thought switching to a custom module would allow me to use the render module but I keep getting the same error I got with the client script. Is there another script type I should be using or is there something wrong with my code?

Error that shows up in the console

Custom module script:

/**
*name.js
*@NApiVersion 2.x
*@NModuleScope Public
*/

define(['N/record', 'N/render'], 

/**
* 
* @param {record} record 
* @param {render} render 
* @returns 
*/



  function (record, render) {

      function customButtonSendInvoice(transaction){
          console.log("The button is working.")
      }

      return{
          customButtonSendInvoice: customButtonSendInvoice
      }
  });

User Event script that creates the button:

    /**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/ui/serverWidget', 'N/log', 'N/render'],
    /**
 * @param{serverWidget} serverWidget
 * @param{log} log
 * @param{render} render
 */
    (serverWidget, log, render) => {
        /**
         * Defines the function definition that is executed before record is loaded.
         * @param {Object} scriptContext
         * @param {Record} scriptContext.newRecord - New record
         * @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
         * @param {Form} scriptContext.form - Current form
         * @param {ServletRequest} scriptContext.request - HTTP request information sent from the browser for a client action only.
         * @since 2015.2
         */
        const beforeLoad = (scriptContext) => {
            try{
                const form = scriptContext.form;
                var transaction = scriptContext.newRecord.getValue({fieldId: 'tranid'});
                form.addButton({
                    id: 'custpage_send_invoice_button',
                    label: 'Send Invoice',
                    functionName: `customButtonSendInvoice("${transaction}")`
                }); 
                form.clientScriptModulePath ='SuiteScripts/BHM Customizations/name.js'
                
            }
            catch(e){
                log.error({
                    title: e.name,
                    details: e.message
                })
            }
        }
        
        return {beforeLoad }

    });

2

Answers


  1. There’s nothing obviously wrong with your code. As long as you are calling that from a server script (which you should include) it should work.

    However NetSuite has been picky about the formatting of the script type annotation. The issue may be as simple as adding spaces. So from:

    /**
    *name.js
    *@NApiVersion 2.x
    *@NModuleScope Public
    */
    

    to

    /**
    * name.js
    * @NApiVersion 2.x
    * @NModuleScope Public
    */
    
    Login or Signup to reply.
  2. As Brett says, "as long as you’re calling that from a server script" it should work. But your screenshot looks suspiciously like the Chrome devtools, which means it’s running as a client script. The usual way to do this sort of thing would be to put your "working" code into a Suitelet, and call the suitelet from the client script.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search