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 triggers before jumping into a sample script project since it is important to have a good basic understanding of these triggers.

Before Submit Trigger

The beforeSubmit function in User Event Scripts are triggered when a record is saved but before the record information is submitted to the database. You may want to use this trigger at times when you need to make last minute field changes to the record before the record is actually submitted.

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

  • When an item is created and saved, automatically set a custom stock number.
  • When a transaction is saved, automatically set a custom field based on line item calculations.
  • when a transaction is created and saved, automatically look up the primary contact from the customer record and enter it in a custom field.

User Event Basic Structure

In the last tutorial we put together the basic sctructure of a User Event Script. Here is what we put together.

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

    //everything else will go inside here
});

Before Submit Basic Structure

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

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

And the return section will look like this.

return {
    beforeSubmit: beforeSubmit
}

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 beforeSubmit(context) {
    //all your Before Submit actions will go in here.
}

return {
    beforeSubmit: beforeSubmit
}
});

If you need to use multiple triggers in a User Event script, this is what your code will look like. This includes the beforeLoad and beforeSubmit triggers.

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.
}

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

return {
    beforeLoad: beforeLoad,
    beforeSubmit: beforeSubmit
}
});

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

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...

Client Scripts Vs. User Event Scripts

Many of the tutorials in this series have been about the Client Script. If you have been following along, you should understand how to create and use client scripts in different basic scenarios. Now we can start touching on the basics of User Event scripts. When we...

Message Module

You may have noticed that NetSuite displays messages as a colored banner at the top of the page. When you enter a transaction you will see a green banner that tells you the transaction was created successfully. That same message functionality is available to use in...

Client Script Validate Field Function

The purpose of the validateField client script function is to control what can and can't be entered in a certain field. One example of how you might want to place controls on a field is with the Job Title field on the customer record. You might want it to be at least...

Client Script Save Record Function

The saveRecord client script function is beneficial when you want to prevent a user from saving a record if certain conditions are true. For instance, if you want to prevent a Purchase Order from being saved if the quantity of a particular item is under a certain...

Client Script Field Changed Function

So far in the sample script we have been working with the "pageInit" function. That function is triggered as soon as you load a record to edit it. In this tutorial we will look at the "fieldChanged" function to explore more ways client scripts can be used. Field...

Set Record Field Values

Getting and setting field values on NetSuite records are some of the most common actions you will do with suitescript. So it is a good idea to get a really good handle on these at the beginning. If you missed the tutorial on getting field values, you can take a look...

SuiteScript Logging and Debugging

In this tutorial we will talk about the basics for how you can figure out problems that come up when you are scripting. If you have been following along with this tutorial series, you may already have run into script errors or other issues that caused your script not...
0
Would love your thoughts, please comment.x
()
x