07

Using SuiteScript in Workflows

Client Formulas & Workflow Action Scripts

🎯 Learning Objectives

Upon completion of this module, you will be able to:

SuiteScript Formulas

SuiteScript formulas use JavaScript and SuiteScript API functions configured on client triggers. They complement SQL formulas by enabling client-side processing.

⚠️ Version Limitation

Only SuiteScript 1.0 formulas are supported on client triggers. SuiteScript 2.0 functions are NOT supported except as external scripts (Suitelets, User Event Scripts, Workflow Action Scripts). You cannot invoke 1.0 scripts from 2.0 scripts.

Syntax Rules

Common SuiteScript 1.0 API Functions

Function Purpose
nlapiGetFieldValue('fieldId') Get field value
nlapiSetFieldValue('fieldId', value) Set field value
nlapiGetFieldText('fieldId') Get display text of list field
nlapiLookupField(type, id, fields) Look up field value on another record
nlapiGetUser() Get current user's internal ID
nlapiGetRole() Get current user's role ID

SuiteScript Formula Example

Validate rating code is less than 10 characters:

nlapiGetFieldValue('custrecord_rating_code').length < 10

⚠️ Server Trigger Warning

If you configure a SuiteScript 1.0 formula on a server trigger, it will be ignored and show "ERROR: Invalid expression" in the log. The warning indicates unrecognizable code—the record submit still completes.

Workflow Action Scripts

What happens when you need to perform an action not supported by standard SuiteFlow actions? This is where Workflow Action Scripts extend SuiteFlow through code.

What Are Workflow Action Scripts?

✅ Use Cases

Complex calculations, external integrations, advanced record manipulation, custom notifications, sublist processing beyond standard actions.

Creating Workflow Action Scripts

Script Structure (SuiteScript 2.0)

/**
* @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 Object

Property Description
scriptContext.newRecord The record being processed
scriptContext.oldRecord Previous version of record (on edit)
scriptContext.workflowId Internal ID of the workflow
scriptContext.type Event type (create, edit, etc.)

Deployment Process

  1. Create Script Record: Upload script file, set Script Type = Workflow Action
  2. Create Deployment: Deploy script, set status to Released
  3. Configure Parameters: Define any custom parameters
  4. Use in Workflow: Add Custom Action, select deployed script

Custom Action Configuration

In the workflow designer:

  1. Click New Action
  2. Select Custom Action from action list
  3. Choose the deployed Workflow Action Script
  4. Configure trigger (server triggers only)
  5. Set any script parameters
  6. Configure conditions as needed

💡 Return Values

Workflow Action Scripts can return values that are stored in workflow fields or used by transition conditions. Define the return type in the script deployment.

SQL vs. SuiteScript Summary

Aspect SQL Formulas SuiteScript Formulas
Trigger Type Server triggers Client triggers
Execution Location NetSuite server/database User's browser
Field Reference {field_id} 'field_id' in API calls
API Version N/A (SQL) SuiteScript 1.0 only
Best For Database operations, calculations UI interactions, client validation

🌟 Key Takeaways