Custom Button and Action with User Event and Suitelet in NetSuite

Enhancing the user interface in business management systems like NetSuite can significantly improve workflow efficiency. The following script demonstrates how to add a custom button to an invoice record, allowing users to accept wire transfers directly from the invoice view using a user event script and a Suitelet.

Code Overview

This script checks if the current record is an open invoice in view mode and adds a custom button to the form.

if (scriptContext.newRecord.type == "invoice" && scriptContext.type == "view" && scriptContext.newRecord.getValue("status") == "Open") {
    let newRecordObj = scriptContext.newRecord;
    let invoiceId = newRecordObj.id;
    const FORM = scriptContext.form;


    let suiteletURL = url.resolveScript({
        scriptId: 'customscript_grw_026_sl_accept_wire_tran',
        deploymentId: 'customdeploy_grw_026_sl_accept_wire_tran',
        params: {
            invoice_id: invoiceId,
            currency: newRecordObj.getText("currency"),
            customer_id: newRecordObj.getValue("entity"),
        }
    });


    // Adding Button named Accept Wire Transfer in the record
    FORM.addButton({
        id: "custpage_grw_026_accept_wire_tran",
        label: "Accept Wire Transfer",
        functionName: "window.open('" + suiteletURL + "')",
    });
}


Key Components

  • Record and Context Check:
  • The script runs only if the record type is invoice, the context is view, and the invoice status is Open.
  • Retrieve Record Details:
  • Fetches the invoice ID, currency, and customer ID from the current invoice record.
  • Generate Suitelet URL:
  • Uses url.resolveScript to create a URL for the Suitelet that handles wire transfers, passing necessary parameters.
  • Add Custom Button:
  • Adds a button labeled “Accept Wire Transfer” to the invoice form.
  • The button opens the Suitelet URL in a new window when clicked.

Leave a comment

Your email address will not be published. Required fields are marked *