Workflow Triggers, Event Types and Contexts

08/01/2022 01:39 PM - By MavenCloud

All actions, transitions and functions within workflows are based on triggers, event types, contexts and conditions.  NetSuite defines triggers for when a workflow should initiate, when actions should be performed, or when a record should transition to another state for the record, based on the processing of a record in NetSuite.  The multitude of options within each of these categories provides almost unlimited control over how your workflow will interact with records so you can be sure it will only effect records WHEN and HOW you want them to be effected.

SuiteFlow includes two types of triggers, server triggers and client triggers:
In general, the type of trigger you use in SuiteFlow depends on when you want a workflow to either initiate or complete a specific action or transition. For example, if you want to alert users that they must change a field value before they submit the record, issue an alert on a client trigger. If you want to notify users after they submit the record with a system error, issue an alert on a server trigger.
A good rule of thumb is if you'd like the action to happen while the user is interacting (or editing) the record that is usually a client trigger, but if you would like the action to happen before OR after the user interacts with the record, it is considered a server trigger.
(NOTE: You can only initiate workflows on server triggers.)

The diagram below shows the types of triggers and whether they are considers server or client triggers.

Client triggers are very helpful to use to "guide" the user on how to fill out the form or record.  Actions like setting fields as mandatory or sourcing a value into a field when another field is edited or changed, are great ways to enhance the user experience during the data entry process.  They can also provide much needed control over your data entry to increase your data integrity.
Server triggers are great to use when you don't want to involve the user in the change or update.  If you would like the user to fill out the form or record with the data they have, and then use that data to provide "default" values or source values into other fields, this is where a server trigger will shine.

Limiting the actions that a workflow performs can improve its design. Likewise, choosing the correct type of trigger optimizes workflow execution and reduces the potential for missing information. This is especially important for workflows that execute on a client trigger, as they involve the user interacting with the interface.
You can initiate a workflow or transition to another state on any of the server triggers or set up actions to execute on the server and client triggers. The triggers supported for actions depend on the type of action.

Server Triggers

Server triggers occur when a record is read from or written to the NetSuite database or when a record enters or exits a state in a workflow. Server triggers are classified as either record based, workflow based, or time based.

Record based triggers occur when something happens to the record:

  • Before Record Load - when the user clicks on the view or edit link for a record and it navigates to a new page.  The loading of this record is considered Before Record Load.
  • Before Record Submit - when the user clicks the Save button on the record but BEFORE the new data is saved to the database.
  • After Record Submit - when the user clicks the Save button on the record the new data is first saved to the database, then the record is loaded again and performs the action.


Workflow based triggers occur when something happens to the workflow

  • Entry - NetSuite is tracking what state the record is in or transitioning between so when it enters a new state it can trigger an action.
  • Exit - NetSuite can trigger an action to happen while the record is "leaving" one state as it transitions to another.
  • Scheduled - the user can define a time based trigger to schedule when an action or transition should occur.


Workflows will evaluate and execute all actions in a state for a specific server trigger before they evaluate and execute the transitions for that trigger.


The following table describes the server triggers and the type of workflow tasks to which they apply:
 Trigger NameApplies ToDescription
Before Record LoadWorkflow Initiation
Actions
Transitions
Triggers while a record is loaded in the browser upon create or edit.
Usually used for setting default fields on records.
 Before Record Submit Workflow Initiation
Actions
Transition
 Triggers when a user clicks the Save button but BEFORE the data is saved to the database
Usually used for validating form data or even calculating fields before save
After Record SubmitWorkflow Initiation
Actions
Transitions
 Triggers when the user clicks the Save button but AFTER new data is saved to the database.
Usually used for transitions or actions dependent on or using new data that is entered onto the record.  Like sending an email or creating depending on records.
EntryActions
Transitions
 Occurs when the record first enters the workflow state.  This trigger fires at the same time as the first server trigger.
Usually used in approval workflows to set statuses or fields dependent on the step of approval process the record is in.  This allows actions to be performed when a record moves from Pending Approval to Approved but NOT every time the record is loaded or edited.
ExitActions
Transitions
 Occurs when the record leaves the workflow state.
Usually used in approval workflows to set statuses or fields dependent on the step of approval process the record is in.  This allows actions to be performed when a record moves from Pending Approval to Approved but NOT every time the record is loaded or edited.
ScheduledWorkflow Initiation
Actions
Transitions
 Trigger an action, transition or initiate a workflow on a schedule
ALLWorkflow Initiation Initiates on any triggering event. (Only used for workflow initiation.)

Client Triggers

Client triggers execute when a user interacts with a record form in NetSuite.  Interactions with records from a client perspective are things like opening a record to view or edit it, or even changing a field value.  Usually if the record is in edit mode then client triggers are being executed.  Client triggers are always record based.

The following table describes the client triggers:
 Trigger NameDescription
 Before User Edit Executes when the record form loads into the browser.
Use this trigger, for example, to make changes to the record form in the browser before the user edits any field. (This is the only trigger we've successfully used to change the Custom Form dynamically before the user interacts with it.)
Before Field Edit Executes when user tabs or clicks away from a field after entering a value.
Use this trigger, for example, when validating the value of a record field.
After Field Edit Executes when a user enters or changes the value of a field.
Use this trigger to help enhance the data entry experience by dynamically performing actions in real-time as fields on the record are being changed.
After Field Sourcing Executes after a field change, after all of the child field values for the field are sourced.
Use this trigger, for example, when setting field values based on other sourced values.
Before User Submit Executes every time a user clicks Save when the form is in the state. The actions execute in the browser, before any data is sent to the NetSuite database and the save operation occurs.
Use this trigger, for example, when validating record form field values.

Event Types

You can extend the detail and control of the actions and transitions by leveraging the event types available in workflows.  These event types represent specific NetSuite events that can affect records and therefore you can only trigger an action when these specific events happen.  For example, if you only want to perform an action when someone creates a drop shipment, or when a user copies a record from another record then this is possible using Event Types.

Simply set the event type in the multi-select field and the action will only respond when that specific event occurs.  If you do not select ANY event type then NetSuite will consider ALL events as available to trigger the workflow, action or transition.


The event types available are:

 Event Types Trigger TypesDescription
 Approve Before Record Submit
After Record Submit
A record is approved using native approval functionality.  (Applies to only transactions listed in the Approval Routing tab of Setup > Accounting Preferences)
 CancelBefore Record Submit
After Record Submit
A transaction is cancelled
Copy Before Record LoadWhen a record is copied from another record
CreateBefore Record Load
Before Record Submit
After Record Submit
A new record is created
DeleteBefore Record SubmitA record is deleted
Direct List EditBefore Record Submit
After Record Submit
A field on a record is updated using inline edit within a saved search
Drop ShipAfter Record SubmitA purchase order is created using the drop ship link
EditBefore Record Load
Before Record Submit
After Record Submit
A record is edited using the "Edit" button in the normal UI
Edit ForecastBefore Record SubmitA forecast is edited using the bulk edit forecast feature
EmailBefore Record LoadAn Email is sent
Mark CompleteBefore Record SubmitA task is marked complete
Order ItemsAfter Record SubmitA transaction is created using the order items screen
PackBefore Record SubmitAn Item Fulfillment is marked packed
Pay BillsAfter Record SubmitBill payment records are created using the bulk pay bills screen
PrintBefore Record LoadA user clicks the print button
ReassignBefore Record SubmitA lead or prospect is reassigned to a new sales rep
RejectBefore Record SubmitA transaction is rejected using native approval functionality.  (Applies to only transactions listed in the Approval Routing tab of Setup > Accounting Preferences)
ShipBefore Record Submit
After Record Submit
An Item Fulfillment is marked shipped
 Special Order After Record SubmitA purchase order is created using the special order link
ViewBefore Record LoadA record is viewed or loaded in the UI

Contexts

You can also specify a certain context to trigger actions or transitions.  This is especially useful when you have a lot of different types of interactions or integrations with your system.  For example, you can trigger an action only when a record is updated using CSV import, or if a record is updated by web services (ie. integration).
Be careful when using contexts as you don't want to limit yourself too much.  Maintaining workflows with lots of context restrictions can be difficult and time consuming.  As your business and processes evolve so will your requirements so constantly changing contexts on actions can become tedious very quickly.


The table below describes all the execution context types in more detail:

 ContextDescription
Action Represents when a record is changes via an action within a workflow
Bank ConnectivityRepresents when a record is changed via the Bank Connectivity plug-in
Bank Statement ParserRepresents when a record is changed via the parser plug-in or Bank Statement Parser plug-in
 Bundle InstallationRepresents when a record is updated via a bundle installation script
ClientRepresents when a record is updated via a client script
CSV Import Represents when a record is updated via CSV import
Custom GL LinesRepresents when a record is updated via the custom GL lines plug-in
Custom Mass UpdateRepresents when a record is updated via mass update.
DebuggerRepresents the SuiteScript Debuger
Email CaptureRepresents when a record is created or updated via the email capture plug-in
Financial Institution ConnectivityRepresents when a record is created or updated via the financial institution connectivity plug-in.
Map/ReduceRepresents when a record is created or updated via a map/reduce script
 OtherRepresents a context that is NOT one of the other contexts listed
Payment PostBackRepresents a payment PostBack task
Payment ProcessingRepresents a payment processing task
Platform Extension
Represents a platform extension customization in Commerce
PortletRepresents a portlet script.
PromotionsRepresents a promotion in Commerce
Rate AdjustorRepresents when a record is updated via the currency rate adjustor
Rest Web ServicesRepresents a REST Web Services request
RESTletRepresents when a record is created or updated via RESTlet script.
Revenue Management
Represents an Advanced Revenue Management task
Scheduled ScriptRepresents when a record is created or updated via Scheduled Script
SDF InstallationRepresents an SDF Installation (SuiteApp Install) script
Shipping PartnersRepresents when a record is updated via a Shipping Label Integration task
SOAP Web ServicesRepresents a SOAP Web Services request
SuiteletRepresents when a record is created or updated via a Suitelet script.
Tax EngineRepresents a SuiteTax Engine Task
User Event ScriptRepresents when a record is created or updated via a User Event script
User InterfaceRepresents when a record is created or updated via the normal user interface that most interact with.
Web ApplicationRepresents when a record is created or updated using a web application in commerce
Web StoreRepresents a web store task in Commerce
WorkflowRepresents a workflow task.

As you can see there can be a very high level of complexity to your workflows with all the different features and options available.  Be very careful in using Event Types and Contexts in your workflows as if you set too many limitations it can be hard to troubleshoot when actions or transitions to not trigger as expected.  Also, as your business grows it will be very difficult to remember and maintain all these specific limitations.  As a best practice we recommend leaving the Event Types and Contexts selection blank (so ALL will be considered) and utilize the Triggers to limit when actions and transitions should occur.
We find it more useful to limit workflows by Event Types and Contexts in only very specific use cases and to even segment those into their own workflow so you can remember to maintain and manage them correctly, without it getting mixed into more general workflows.


If you need more help getting started with workflows, be sure to read through our Creating Your First Workflow post to start with a basic approval workflow and get a good foundation to build upon.

MavenCloud