SuiteScript 2.x Workflow Action Script Type
Workflow action scripts let you create custom Workflow Actions on a record in a workflow. They’re handy for working with sublists since sublist fields aren’t available through the Workflow Manager. You can also use workflow action scripts to run advanced logic you can’t do with built-in actions.
For more on SuiteFlow workflows, check out these topics:
For details about scripting with workflow action scripts, see Creating and Using Workflow Action Scripts and SuiteScript 2.x Workflow Action Script Entry Points and API.
You can use SuiteCloud Development Framework (SDF) to manage these scripts in file-based projects. For more, see SuiteCloud Development Framework. Use the Copy to Account feature to copy a workflow action script to another account. Just click Copy to Account at the top right. For more info, see Copy to Account.
You can use SuiteScript Analysis to see when the script was installed and how it’s performed. To learn more, see Analyzing Scripts.
Workflow Action Script Sample
This sample shows how to save a return value from a custom action script to a workflow field.
-
You want to get a value from the Item sublist and use the value as a condition in the workflow. You use
record.getSublistValue
in the script and return this in the workflow. -
You want to check if a certain item exists in the Item sublist. The script returns "0" if it doesn’t and "1" if it does.
-
You want to make sure that all items in the Item sublist have a quantity equal to or greater than 1 (similar case as above).
Before you use this script, make sure you’ve done the following:
-
Make sure the script returns a value—you can set this on the Parameters tab of the Script record page.
-
In SuiteFlow, create a workflow field that matches the data type of the script return value.
-
In a workflow state, add the custom action (your Workflow Action script).
-
Add the Workflow Action script’s return value to the Store Result In field under custom action Parameters.
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
*/
define([], function() {
function onAction(scriptContext){
log.debug({
title: 'Start Script'
});
var newRecord = scriptContext.newRecord;
var itemCount = newRecord.getLineCount({
sublistId: 'item'
});
log.debug({
title: 'Item Count',
details: itemCount
});
for (var i = 0; i < itemCount; i++){
var quantity = newRecord.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: i
});
log.debug({
title: 'Quantity of Item ' + i,
details: quantity
});
if (quantity === 0){
return 0;
}
}
log.debug({
title: 'End Script'
});
return 1;
}
return {
onAction: onAction
}
});
See the SuiteFlow help topics for additional samples, such as Storing a Return Value from a Custom Action Script in a Workflow Field. You can find more examples if you search “workflow action script” on Suite Answers—some may be in SuiteScript 1.0.
Related Topics
- SuiteScript 2.x Script Types
- SuiteScript 2.x Bundle Installation Script Type
- SuiteScript 2.x Client Script Type
- SuiteScript 2.x Map/Reduce Script Type
- SuiteScript 2.x Mass Update Script Type
- SuiteScript 2.x Portlet Script Type
- SuiteScript 2.x RESTlet Script Type
- SuiteScript 2.x Scheduled Script Type
- SuiteScript 2.x Suitelet Script Type
- SuiteScript 2.x User Event Script Type