NetSuite Workflow Action Script Generator for SuiteFlow Custom Actions
This tool generates a SuiteScript 2.1 workflow action script for NetSuite SuiteFlow: an onAction entry point that reads a script parameter, inspects the record and returns a value the workflow stores in a field. The default example escalates vendor bills above a threshold to the running user's supervisor.
Fill in
Workflow action script
/**
* @NApiVersion 2.1
* @NScriptType WorkflowActionScript
*
* Purpose: Return the next approver for bills above the threshold
* Record type: vendorbill
* Return Type on the script record: List/Record (Employee)
*/
define(['N/runtime', 'N/search', 'N/log'], (runtime, search, log) => {
const onAction = (scriptContext) => {
const rec = scriptContext.newRecord;
const script = runtime.getCurrentScript();
const paramValue = script.getParameter({ name: 'custscript_wa_threshold' });
const threshold = paramValue ? Number(paramValue) : 5000;
const total = Number(rec.getValue({ fieldId: 'total' }) || 0);
const currentApprover = rec.getValue({ fieldId: 'nextapprover' });
log.debug({
title: 'onAction',
details: 'workflowId=' + scriptContext.workflowId + ' type=' + scriptContext.type +
' record=' + rec.type + ':' + rec.id + ' total=' + total + ' threshold=' + threshold
});
// At or below the threshold keep the current approver
if (total <= threshold) {
return currentApprover || '';
}
// Above the threshold route to the supervisor of the user running the workflow
const userId = runtime.getCurrentUser().id;
const lookup = search.lookupFields({
type: search.Type.EMPLOYEE,
id: userId,
columns: ['supervisor']
});
const supervisor = (lookup.supervisor && lookup.supervisor.length) ? lookup.supervisor[0].value : '';
log.audit({ title: 'escalated', details: 'user ' + userId + ' -> supervisor ' + supervisor });
return supervisor || currentApprover || '';
};
return { onAction };
});Script record and workflow setup
| Step | Where | Setting |
|---|---|---|
| 1 | Customization > Scripting > Scripts > New | Upload the file, script type Workflow Action |
| 2 | Script record, Parameters | Add custscript_wa_threshold (Decimal Number or Integer) and set the default on the deployment |
| 3 | Script record | Set Return Type to List/Record (Employee); for List/Record also set the list or record to Employee |
| 4 | Script deployment | Applies To: vendorbill, Status Released, Log Level Debug while testing |
| 5 | Workflow state | New Action, choose the custom action by script name, set trigger and condition |
| 6 | Custom action, Store Result In | Pick a workflow field or record field of a matching type (e.g. Next Approver) |
Verify on your release: the 1,000 usage unit limit for workflow action scripts is shared by all actions in the same workflow state. The returned value must match the Return Type on the script record, and a List/Record return must be an internal id of the declared record type. Test with a user who has a supervisor set.
Get your workflow action reviewed
Send the script and the workflow state it runs in and we will check triggers, return type and usage against the 1,000 unit state limit.
Optional. The tool and every export work without this. No spam.
How to use it
Set the record type, the parameter id that holds the threshold, the fallback threshold and the field holding the current approver, then pick the Return Type you will set on the script record. Copy the code into a .js file, upload it, create the script record and deployment, and add it to a workflow state as a custom action. In the action, use Store Result In to write the returned value into a workflow field or record field. Workflow action scripts are the right tool when SuiteFlow conditions and formulas cannot express the logic, for example a lookup on another record, a calculation across lines or a call to a saved search.
- Script parameter ids must start with custscript.
- Give each action a clear trigger (Before Record Load, Before Record Submit, After Record Submit, or On Entry) and condition.
What the onAction context gives you
The entry point receives scriptContext with newRecord (the record in the workflow), oldRecord (the previous version on edit), form (on before load triggers), type (the event type) and workflowId (the internal id of the running workflow). The script runs inside the workflow, under the same trigger as the action, so its record changes and returned value become part of that workflow step. If the action runs on After Record Submit, changes to newRecord are not saved automatically; return the value and let Store Result In or a Set Field Value action write it.
Governance and return types
Oracle help gives workflow action scripts 1,000 usage units, and the limit applies to all actions in one workflow state combined. A single search.lookupFields call is cheap, but record.load and save calls inside a state that also sends email can exhaust it. The value returned must match the Return Type on the script record, which uses field types such as Free-Form Text, Integer Number, Check Box or List/Record; List/Record needs the record type set and the script returns an internal id. If the type does not match the Store Result In field, the action fails or stores nothing.
- Return an empty string, not null, when there is nothing to set.
- Log workflowId and type while testing so the execution log shows which workflow ran the script.
How to check it worked
Create a test vendor bill above the threshold as a user with a supervisor. On the bill, open the Workflow History subtab (System Information) to see the state entered and the action run, then check the script deployment execution log for the onAction and escalated entries. Repeat just below the threshold and confirm the current approver is kept.
Frequently Asked Questions
What is a workflow action script in NetSuite?
It is a SuiteScript type with a single onAction entry point that SuiteFlow calls as a custom action inside a workflow state. It lets a workflow run logic that standard actions such as Set Field Value cannot express, and it can return a value that the workflow stores in a field through Store Result In.
Can a workflow set a field value without a script?
Yes. The standard Set Field Value action sets a static value, a value from another field, or a formula result, and covers most cases. Use a workflow action script only when the value needs a lookup on another record, a search, a line-level calculation or logic too long for a formula.
What is the governance limit for workflow action scripts?
Oracle help lists 1,000 usage units for workflow action scripts, applied per workflow state with all actions in that state combined. Plan the expensive calls accordingly, and move heavy processing such as transforming or saving many records to a scheduled or map/reduce script triggered by the workflow.
Where do I set the return type of a workflow action script?
On the script record, set the Return Type to match what onAction returns, and for a List/Record return choose the record type as well. Then, in the workflow custom action, set Store Result In to a field of the same type. A mismatch is the usual reason the stored value is blank.
If you want approvers and AP staff to ask NetSuite about stuck approvals and workflow history in plain English, with answers grounded in your own records, we can set that up privately.
Related Tools
NetSuite Vendor Bill Approval Workflow Design Template
Fill in tier limits and approvers to get a SuiteFlow design document with states, transitions, approval status values, emails and test cases.
Developer ToolsNetSuite SuiteScript N/query runSuiteQLPaged Snippet Generator
Paste a SuiteQL statement and get SuiteScript 2.1 code that runs it with bound parameters, single-shot or paged, with a governance check.
NetSuiteNetSuite Script and Workflow Inventory Worksheet
An editable inventory of the scripts, workflows and scheduled jobs in your NetSuite account, with owners, schedules, daily run minutes and risk level.
NetSuiteNetSuite SuiteScript Governance Units Estimator
Estimate how many records a SuiteScript execution can process under its governance limit and how many runs a batch will need.
More Developer Tools tools
See all- NetSuite SuiteScript 2.1 RESTlet Skeleton Generator
- NetSuite SuiteScript Governance Units by Script Type
- NetSuite API Retry Backoff Wait Time Calculator
- NetSuite OAuth 2.0 Access Token Refresh Calculator
- NetSuite REST Web Services Headers and Query Parameters Reference
- SuiteScript 1.0 to 2.1 API Mapping Reference for NetSuite
- NetSuite REST API SuiteQL Request Generator
- NetSuite REST API Sales Order and Journal Entry Request Generator
- NetSuite Token-Based Auth OAuth 1.0 Signature Code Generator
Keep exploring
Free tools
- SuiteScript 2.1 Client Script Generator for NetSuiteGenerate a working client script for a transaction or customer form: field checks, line validation with a dialog, sublist totals and a save guard, exporting only the entry points you pick.
- NetSuite SuiteScript 2.1 RESTlet Skeleton GeneratorFill in a script name, record type and fields to get a SuiteScript 2.1 RESTlet with GET lookup, POST create, logging and error handling.
- SuiteScript 2.1 Scheduled Script Generator for NetSuiteGenerate a restartable scheduled script that processes a saved search in internal ID order, checks remaining usage and resubmits itself before hitting the 10,000-unit limit.
ERP fixes and how-tos
- How to build a workflow in NetSuite with SuiteFlowStep-by-step guide to building a NetSuite SuiteFlow workflow: record type, trigger, states, transitions, actions, and why workflows silently do not fire.
- N/query versus N/search: choosing the right SuiteScript data access moduleCompare NetSuite's N/query (SuiteQL) and N/search modules for performance, governance cost and capability, and decide which to use for joins, aggregation, sublist reads and large exports in SuiteScript 2.1.
- Avoiding governance limit errors in NetSuite Map/Reduce scriptsUnderstand how governance is allocated per key in NetSuite Map/Reduce scripts, why SSS_USAGE_LIMIT_EXCEEDED still happens, and how to design getInputData, map, reduce and summarize stages that do not time out.
Integrations
- How to add WhatsApp to Oracle NetSuiteHow to connect WhatsApp Business to Oracle NetSuite: SuiteScript triggers, RESTlets, template messages, opt-in rules and two-way replies that post back to records.
- How to integrate Microsoft Teams with Oracle NetSuiteConnect Oracle NetSuite to Microsoft Teams: approval cards, alerts, bots and Entra ID sign-in using SuiteScript, RESTlets and Power Automate or Bot Framework.