Don’t Miss it: Top Strategies for Driving Diversity

days / hours / minutes / seconds

Register Here »
NetSuite logo
NETSUITE RESOURCES
workplace by meta logo
FUTURE
OF WORK WORKPLACE BY META
University icon
CUSTOMER EDUCATION blog
Atlassian Logo
Adoption blog
How-to
December 14, 2023
|
4.5 min
reading time

NetSuite 101: Which Executes First, User Event Scripts or Workflows?

Share this article
/*SoMe buttons*/ <-- Facebook Share Button Code --> <-- Facebook Share Button Code --> <-- Twitter Share Button Code --> <-- Twitter Share Button Code --> <-- Linkedin Share Button Code --> <-- Linkedin Share Button Code -->

As a NetSuite developer, you might ask this question at some point: Which executes first on NetSuite records, the user event script or the workflow?

To help you answer this question, ServiceRocket’s Senior Director, Partner Success, Lea Columna, walks you through her experimentation process. Read on to hear directly from her on how she finds the answer.

Which Executes First, The User Event Script or the Workflow?

This is one question that deserves an explanation since some scenarios in the scripting world require an understanding of this subject. So, I thought I’d do an experiment and document what I found. 

For those who want the quick answer, here it is: in a NetSuite record, user event script runs first, then workflows, as long as they are within the same entry point.

But for those interested in a more in-depth answer, read on to learn more about how this experiment went.

Before Submit User Event Script vs. Before Submit Workflow

In my experiment, I have a workflow with the following configuration: Deployed to: Sales Order, Event Type: is on View or Update, Trigger Type: Before Record Submit.  

I only have one action, which is: Set Field Value

Below are the parameters: Set Field Value: Memo=workflow memo. 

 

You can see the sample snippet below:



function beforeSubmit_func(context){ 
    var currentRecord = context.newRecord;
 
    currentRecord.setValue({ 
        fieldId: 'memo', 
        value: 'script memo' 
    });
    
    log.debug("Triggered Before Submit"); 
}


The script configuration is: Trigger On: Before Record Submit, Deployed To: Sales Order

I took the screenshot of what was set in the Memo field after editing and saving the Sales Order.  

You will see in the actual screenshot that the record picked up the memo set by the workflow. So what happened to the script? Well, it was executed. However, the value that was reflected on the record wasn’t the one set by the script. The value got overridden by the workflow. 

Here’s the screenshot of the field when I set the workflow to Not Running. The value reflected the one set by the script.  

If you’re still unconvinced, let’s look at the System Notes

Note: Don’t mind the Context column. That merits a separate discussion.

Here, you can see that at 4:40 pm, when I un-deployed the workflow, the record picked up the value set by the script. So, in this case, the Before Submit User Event script goes first, with the Before Submit Workflow coming after.

After Record Submit Script vs. Before Record Submit Workflow

Here’s another scenario: What if the script is on After Record Submit and the workflow is on Before Record Submit? Will the script still trigger first? Let’s find out. Here’s my sample function. The script performs a submitField on After Record Submit:



function afterSubmit_func(context){ 
    var currentRecord = context.newRecord; 
    record.submitFields({ 
        type: currentRecord.type, 
        id: currentRecord.id, 
        values: { 
            memo: 'script memo' 
        }, 
        options: { 
            ignoreMandatoryFields: true 
        } 
    }); 
    log.debug("Triggered After Submit"); 
}

Here’s proof that I deployed it on After Record Submit.

After editing and saving the test order, the Memo displayed, script memo. That means that this time, the script wasn’t executed first.

In this scenario, the workflow is executed first because its trigger type is Before Record Submit.

After Record Submit script vs. After Record Submit Workflow

And finally, what happens if you change the Trigger type of the workflow from Before Record Submit to After Record Submit? If you guessed it right, yes, the Memo got set to workflow trigger again. It followed the “user event scripts first” order. In the below screenshot, notice how the workflow history log displays the After Submit trigger

The Verdict

After all this experimentation, it is clear to say that User Event scripts always trigger before workflows as long as they have the same trigger type. To elaborate, the order goes like this:

User Event Before Submit →Workflow Before Submit User Event After Submit → Workflow After Submit

However, the entry point prevails on which to execute first. This means it can also be:

Workflow Before Submit → User Event After Submit User Event Before Submit → Workflow After Submit

Want more insights like this?

With ServiceRocket, you’ll get certainty, expertise and success built into your NetSuite implementation, configuration and custom development. When you work with us, you get access to NetSuite-trained Certified Developers with over 400+ NetSuite scripts and 50+ Suitelet workflows combined. Rest assured that ServiceRocket will help you find success and provide you with the opportunities you need to transform your business.

Do you have NetSuite license management, implementation, administration, support or custom development needs? We’ve got your back! Contact our NetSuite Certified Experts today.

Ensure the highest return on your NetSuite investment with our custom development or administrative services.

Learn MoreServiceRocket Backed - We've got your back badge