User Event Scripts are one of the most common script types to work with. In the next several blogs I will walk through some example User Event scripts, and this first blog will introduce the basic setup of the Before Load trigger in a User Event script.

Before Load Trigger

The beforeLoad function in User Event Scripts are triggered when a record is loaded. You can do actions as a record loads when it is..

  • Created
  • Copied
  • Edited
  • Viewed

Here are some examples of what can be done with the beforeLoad function in a User Event Script.

  • When a record is created or copied, automatically populate fields based on the current user’s role.
  • When a record is viewed, hide critical information that the current user does not need to see.
  • when a record is edited, automatically update fields when a certain criteria is met.

User Event Basic Structure

The basic structure of User Event Scripts is similar to Client Scripts. You have to include any module that will be needed in the script.

define(['N/record', 'N/search'], function (record, search) {
    //everything else will go inside here

});

In this example, the N/record and N/search modules are being included in the script. They are added to the script here — define(['N/record', 'N/search'], and are given a name to be used in the script — function (record, search).

You also need to add the section that displays information about what the script type is and what the suitescript version is. When you add that in, here is what the script should look like.

define(['N/record', 'N/search'], function (record, search) {
    /**
    *@NApiVersion 2.0
    *@NScriptType UserEventScript
    */

    //everything else will go inside here
});

Before Load Basic Structure

The beforeLoad trigger can be added to the script by adding the beforeLoad function and then adding it to the return section of the script. Here is what the basic beforeLoad function looks like.

function beforeLoad(context) {
    //all your Before Load actions will go in here.
}

And the return section will look like this.

return {
    beforeLoad: beforeLoad
}

When you add that to the rest of the script, it will look like this.

define(['N/record', 'N/search'], function (record, search) {
    /**
    *@NApiVersion 2.0
    *@NScriptType UserEventScript
    */

function beforeLoad(context) {
    //all your Before Load actions will go in here.
}

return {
    beforeLoad: beforeLoad
}
});

In the next tutorial, we will take this basic structure and add to it to create an example Before Load customization.

Check out other blogs in our NetSuite Development series and subscribe below to never miss another post!

    SuiteScript 2.0 Creating Pop-ups: The Dialog Module

    Creating custom pop-ups can be super helpful when implemented correctly. Our previous blog will help give you some ideas for your own use cases. Today we will walk you through creating your own. Having covered some of the foundational script types in SuiteScripting,...

    3 Reasons You Should Switch from SuiteScript 1.0 to 2.0

    There are many reasons to consider switching from SuiteScript 1.0 to 2.0. 3 reasons are modularity and compatibility with JavaScript and NetSuite’s APIs.

    SuiteScript 2.0 User Event Script After Submit

    In this blog we touch briefly on the 3rd and final User Event function that is available: the After Submit function. With this basic foundation of the structure and capabilities of each function, we will be ready to dive into some real life examples in the next...

    SuiteScript 2.0 User Event Script Before Submit

    In the last tutorial we looked at the setup of the Before Load trigger for User Event scripts. In this tutorial will introduce the basic setup of the 2nd of 3 main User Event triggers: the Before Submit trigger. I want to spend some time looking at each of these...

    SuiteScript 2.0 User Event Script Before Load

    User Event Scripts are one of the most common script types to work with. In the next several blogs I will walk through some example User Event scripts, and this first blog will introduce the basic setup of the Before Load trigger in a User Event script. Before Load...
    0
    Would love your thoughts, please comment.x
    ()
    x