The N/workflow module allows SuiteScript to initiate and interact with NetSuite workflows programmatically β triggering workflow instances, getting workflow state, and setting field values within workflow actions.
Triggering a Workflow
define(["N/workflow", "N/log"], (workflow, log) => {
const workflowId = workflow.trigger({
recordType: "salesorder",
recordId: 12345,
workflowId: "customworkflow_approval_wf"
});
log.audit("Workflow triggered", workflowId);
return {};
});
Getting Workflow State
const state = workflow.getState({
workflowId: "customworkflow_approval_wf",
workflowInstanceId: workflowId,
recordId: 12345,
recordType: "salesorder"
});
log.debug("Current state", state.id);
Key Methods
| Method | Description |
|---|---|
workflow.trigger(options) | Initiate a workflow instance on a record |
workflow.getState(options) | Get the current state of a running workflow |
workflow.setState(options) | Set the workflow to a specific state |