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

After Submit Trigger

The afterSubmit function in User Event Scripts trigger when a record is saved and after the data gets submitted to the database. This function can be used if you do not need to make last minute changes to a record after saving or if you need to do heavier script actions after saving. You can still make changes to the current record with this action, but you will need to load the record with the script and save it with the script since the record has already been submitted to the database.

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

  • Send an order confirmation email to the customer, when a sales order is created and saved.
  • Automatically create an item fulfillment record if the sales order meets certain conditions, when a sales order is saved. 
  • Automatically create a vendor bill, when an item receipt is created and saved.

After Submit Basic Structure

Here is the basic structure of a User Event script that includes all three triggers that we have discussed in the last several blogs: beforeLoad, beforeSubmit, and afterSubmit.

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

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

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

Notice that a function is added for each trigger, and all actions for the triggers go within the curly brackets. Also notice the way each function is listed in the “return” section of the script. This basic structure is what you will see in all SuiteScript 2.0 scripts.

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

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

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...
0
Would love your thoughts, please comment.x
()
x