📑 In This Module
🎯 Learning Objectives
- Understand SuiteFlow workflow concepts
- Learn workflow elements: states, actions, transitions, triggers
- Create Workflow Action scripts
- Integrate SuiteScript with workflows
1. Understanding Workflows
SuiteFlow is NetSuite's visual workflow builder. It automates business processes without code - but Workflow Action Scripts let you extend it with custom logic.
💡 SuiteFlow vs SuiteScript
- SuiteFlow: Point-and-click automation for business processes
- SuiteScript: Code-based for complex logic and integrations
- Together: Use workflows for process flow, scripts for custom actions
2. Workflow Elements
| Element | Purpose | Example |
|---|---|---|
| State | Where you are in the process | Pending Approval, Approved, Rejected |
| Action | What to do | Send Email, Set Field, Custom Action |
| Transition | How to move between states | If approved → go to Approved state |
| Trigger | When to execute | On Entry, On Exit, Button Click |
Built-in Actions
- Set Field Value
- Send Email
- Create Record
- Go To Record
- Lock/Unlock Record
- Custom Action (SuiteScript!)
3. Workflow Action Scripts
When built-in actions aren't enough, create a Workflow Action Script:
/**
* @NApiVersion 2.1
* @NScriptType WorkflowActionScript
*/
define(['N/record', 'N/email'], function(record, email) {
function onAction(context) {
// context.newRecord = the record being processed
// context.oldRecord = previous version (if edit)
// context.workflowId = workflow internal ID
// context.type = trigger event type
var rec = context.newRecord;
var total = rec.getValue('total');
var customerId = rec.getValue('entity');
// Custom logic here
if (total > 10000) {
// Send notification for large orders
email.send({
author: -5,
recipients: 'manager@company.com',
subject: 'Large Order Alert',
body: 'Order #' + rec.getValue('tranid') +
' total: $' + total
});
}
// Return a value (can be used in workflow conditions)
return 'SUCCESS';
}
return { onAction: onAction };
});
4. Creating Custom Actions
Step 1: Create the Script
Create a WorkflowActionScript file as shown above.
Step 2: Create Script Record
- Customization → Scripting → Scripts → New
- Upload your file
- Save (no deployment needed for Workflow Actions)
Step 3: Add to Workflow
- Edit your Workflow
- Add an Action to a state
- Choose "Custom Action"
- Select your script
- Configure trigger (Entry, Exit, Button)
Returning Values
Your script can return values for workflow conditions:
function onAction(context) {
var total = context.newRecord.getValue('total');
if (total > 10000) {
return 'LARGE_ORDER';
} else if (total > 1000) {
return 'MEDIUM_ORDER';
} else {
return 'SMALL_ORDER';
}
}
// In workflow, add transitions based on return value:
// If return = 'LARGE_ORDER' → go to Manager Approval
// If return = 'SMALL_ORDER' → go to Auto Approved
⚠️ Execution Context
Workflow Action Scripts run server-side. They cannot access client-side features like alerts or DOM manipulation.
🏋️ Practice Exercises
Exercise 1: Basic Action
Create a Workflow Action Script that logs the record type and ID when triggered.
Exercise 2: Conditional Logic
Create an action that returns different values based on order total (use for workflow branching).
🎯 Key Takeaways
- SuiteFlow handles business process automation visually
- Workflow Action Scripts extend workflows with custom code
- Scripts receive context with newRecord, oldRecord, workflowId
- Return values can drive workflow transitions
- No deployment needed - attach directly to workflow states
- Use for logic too complex for built-in actions