Purpose
This article describes how to implement a Workflow Action Script in NetSuite to exclude special or drop ship orders from progressing through a workflow. The script checks if any item line in a transaction has the “Create PO” checkbox selected. If none are selected, the workflow bypasses the state meant for purchase order creation.
Script Code
/**
* Workflow Action Script to check if any item line has “Create PO” checked.
* Used to exclude special or drop ship orders from workflow transitions.
*/
define([], () => {
const onAction = (context) => {
const newRec = context.newRecord;
const lineCount = newRec.getLineCount({ sublistId: ‘item’ });
for (let i = 0; i < lineCount; i++) {
const createPoValue = newRec.getSublistValue({
sublistId: ‘item’,
fieldId: ‘createpo’,
line: i
});
log.debug(“createPoValue…”, createPoValue);
if (createPoValue) {
// At least one item line has “Create PO” checked
return 1;
}
}
// No item lines have “Create PO” checked
return 0;
};
return { onAction };
});
Workflow Configuration
1. Create a Workflow Parameter
- Type: Integer
- Purpose: Store the return value of the script (
1or0)
2. Add a New Workflow State
- Name: “Exclude”
- This state handles orders that require a purchase order.
3. Define Transitions
- If script returns
1(i.e., at least one item line has “Create PO” checked): - Exclude those order
- If script returns
0(i.e., no item lines require PO creation): - Transition to a different state, such as “include”.