In this blog we touch briefly on the 3rd and final User Event function that is available: the User Even Script 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 triggers after a user saves a record and after the data submits to the database. You can use this function 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 you create and save a sales order.
  • Automatically create an item fulfillment record if the sales order meets certain conditions, when you save a sales order.
  • Automatically create a vendor bill, when you create and save an item receipt.

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 the “return” section of the script lists each function. This basic structure is what you will see in all SuiteScript 2.0 scripts.

Conclusion

We hope this blog on the User Even Script After Submit function has been helpful; if you missed our two previous blogs on User Event triggers, be sure to check out them out in the related posts below. And don’t forget to subscribe below to never miss another post!