Workflow Action Script Template
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
define(['N/record', 'N/log'], function(record, log) {
function onAction(scriptContext) {
var newRecord = scriptContext.newRecord;
var workflowId = scriptContext.workflowId;
// Your custom logic here
return 'SUCCESS'; // Return value to workflow
}
return {
onAction: onAction
};
});
Workflow API Functions
workflow.initiate()
Initiates a workflow on demand (equivalent to Initiate Workflow action).
var workflowId = workflow.initiate({
recordType: 'customrecord_perf_review',
recordId: 123,
workflowId: 'customworkflow_approval'
});
workflow.trigger()
Wakes up a running workflow and triggers a virtual button click.
var workflowId = workflow.trigger({
recordType: 'customrecord_perf_review',
recordId: 123,
workflowId: 'customworkflow_approval',
actionId: 'custworkflow_approve_btn'
});
📋 SuiteScript 1.0 Equivalents
nlapiInitiateWorkflow() and nlapiTriggerWorkflow() provide the same functionality in SS 1.0.
Best Practices
- ✓ Use built-in SuiteFlow actions when possible
- ✓ Avoid resource-intensive operations in scripts
- ✓ Use scheduled scripts for batch operations
- ✓ Return meaningful values for workflow conditions
- ✓ Use APM to identify performance bottlenecks
💡 Performance Tip
Workflows wait synchronously for scripts to complete. For complex batch operations, initiate a scheduled script to process asynchronously.