What is Define() function in Netsuite SuiteScript 2.0

In SuiteScript 2.0 , script uses define() function to load the modules before execution

Use the define() function to load SuiteScript 2.0 modules and create custom modules.
When you use the define() function, it loads all dependencies before it executes any logic.
In SuiteScript 2.0, the define() function returns an object that encapsulates the module you are defining.

Developer must use the define() function in his/her entry point script. The return statement must include at least one entry point and entry point function. All entry points must belong to the same script type. 

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record'],
    function (record)
    {
        function method1(context)
        {
            //add your logic here
        }
        function method2(context)
        {
           // add your logic here 
        }
        function method3(context)
        {
            // add your logic here 
        }
        return {
            beforeLoad: method1,
            beforeSubmit: method2,
            afterSubmit: method3
        };
    });

Comments

  1. Can I use define and require function both in same script?

    ReplyDelete
  2. Hi , No we cant use both at same time.
    Also Define return value but Require don't.

    also When you use the define() function, it loads all dependencies before it executes any logic

    where as When you use the require() function, dependencies are not loaded until they are needed.

    ReplyDelete
  3. can i run the script with out both functions.

    ReplyDelete
  4. One at a time.
    not both together. I explained answer above.

    ReplyDelete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin