Search code examples
netsuitesuitescript

In Netuite, is it possible to run a suitescript when a standard button is pressed?


In Netsuite, I want to run a suitescript when a standard button on a transaction record is pressed. Example 'Mark Shipped' button on item fulfillment. Is it possible?

I have tried a client script but it works only when you edit the record.


Solution

  • You can't arbitrarily run a script on just any native button, but in the example you give you can use a User Event script to fire on the ship event.

    /**
     * @NApiVersion 2.x
     * @NScriptType UserEventScript
     * @NModuleScope SameAccount
     */
    
    define([], function() {
        'use strict';
        return {
          beforeSubmit: beforeSubmit
        };
    
        function beforeSubmit(context) {
        
            if (context.type !== context.UserEventType.SHIP) { return; }
    
            //code to run when Item Fulfillment is marked shipped goes here.
        }
    });
    

    Other "action" buttons like Approve, Cancel and Print and so on also fire events that you can listen for. See context.UserEventType in SuiteAnswers for a complete list.