NetSuite 101: Which executes first, User Event scripts or workflows?

You might ask this question one day in your life as a NetSuite Developer:

Which executes first on NetSuite records, is it the user event script or the workflow?

This is one question that deserves an explanation since some scenarios in the scripting world requires an understanding of this subject. So I thought I’d do an experimentation and document what I found. If you hate TLDR; articles, here’s the quick answer for you – in a NetSuite record, user event script runs first, then workflows, as long as they are within the same entry point. Thank you, you may close the browser now. But if you’re interested to read more about how this experiment went on, read on.

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 suiteflow-configuration I only have one action which is: Set Field Value. Below are the parameters: Field to Set: Memo Value: “workflow memo” suiteflow-set-field-value 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 Here’s the screenshot that I took of what was set in the Memo field after editing and saving the Sales Order. 3 memo field 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 executed. However, the value that reflected on the record wasn’t the one set by the script. The value got overridden by the workflow. 4 script log Here’s the screenshot of the field when I set the workflow to “Not Running”. The value reflected the one set by the script. 5 script memo If you’re still not convinced, let’s take a look at the System Notes. Don’t mind the Context. That merits a separate discussion. 🙂 6 system notes log See that at 8:12 am when I un-deployed the workflow, the record picked up the value set by the script. So yeah, before submit user event script goes first, then the before submit workflow comes next.

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 a proof that I deployed it on “After Record Submit”. script-after-submit After editing and saving the test order, the Memo displayed “script memo”. That means that this time, it wasn’t the script that executed first. 5 script memo In this scenario, the workflow executed first because its trigger type is Before Record Submit.

After Record Submit script vs. After Record Submit Workflow

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. Notice how the workflow history log displays the After Submit trigger. 7 workflow after record submit.jpg

Verdict: In a NetSuite record, User Event scripts trigger first  before workflows as long as they are within the same entry point.

I believe we have reached a verdict. User Event scripts always trigger first 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. Meaning to say:

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

Hope this article helps you in some way. Would love to get your feedback by commenting below! LEACC Consulting is a team of NetSuite Certified Developers with IT experience solely dedicated to NetSuite technologies for eight years. We are experts in both SuiteScript 2.0 and SuiteScript 1.0. Our team has worked with 400+ NetSuite scripts and workflows combined. If you need some consulting help of how you can design your NetSuite scripts better, contact us by filling out this form or by commenting below.

Do you have NetSuite Development needs? Do you need help with a solution like this? Click on the link below and let’s have a chat about your project requirements!

Contact us for your NetSuite needs!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s