SuiteScript 2.x Workflow Action Script Type
Workflow action scripts allow you to create custom Workflow Actions that are defined on a record in a workflow. Workflow action scripts are useful for performing actions on sublists because sublist fields are not currently available through the Workflow Manager. Workflow action scripts are also useful when you need to create custom actions that execute complex computational logic that is beyond what can be done with the built-in actions.
For information about SuiteFlow workflows, see the following topics:
For information 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 workflow action scripts as part of file-based customization projects. For information about SDF, see SuiteCloud Development Framework. You can use the Copy to Account feature to copy an individual workflow action script to another of your accounts. Each workflow action script page has a clickable Copy to Account option in the upper right corner. For information about Copy to Account, see Copy to Account.
You can use SuiteScript Analysis to learn about when the script was installed and how it performed in the past. For more information, see Analyzing Scripts.
Workflow Action Script Sample
This sample shows how to store a return value from a custom action script into a workflow field. This sample could be used if:
-
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 item is not existing 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 using this script, the following must be done:
-
Ensure that the script returns a value. You can specify this on the Parameters tab of the Script record page.
-
In SuiteFlow, create a workflow field. The field should be of the same type as the return parameter of the Workflow Action script.
-
Within a state, add the custom action (this is the Workflow Action script).
-
Add the return value from the Workflow Action script to the Store Result In field. This field is found in the custom action’s Parameters. See Storing a Return Value from a Custom Action Script in a Workflow Field.
/**
* @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. Additional samples are also available by searching “workflow action script” on Suite Answers. Note that some samples 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