💻 Appendix C: SuiteScript Reference

Workflow Action Scripts & Integration Functions

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 }; });

Script Context Properties

PropertyDescription
scriptContext.newRecordRecord being processed
scriptContext.oldRecordPrevious version (on edit)
scriptContext.workflowIdInternal ID of workflow
scriptContext.typeEvent type (create, edit, etc.)

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.

Deployment Steps

  1. Upload script file to File Cabinet
  2. Create Script Record (Script Type = Workflow Action)
  3. Create Deployment (Status = Released)
  4. Configure any custom parameters
  5. In workflow: Add Custom Action → Select deployed script

Best Practices

💡 Performance Tip

Workflows wait synchronously for scripts to complete. For complex batch operations, initiate a scheduled script to process asynchronously.

← Back to Course Overview