Storing a Return Value from a Custom Action Script in a Workflow Field
This sample shows how to store a return value from a custom action script into a workflow field. This example can be useful in the following cases:
-
You want to get a value from the Item sublist and use this value as a condition in the workflow. You use obj.getSublistValue in the script and return this in the workflow.
-
You want to check if a certain item is existing 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 #2).
To store a return value from a custom action script in a custom field:
-
Create a new Workflow Action script.
This script is an example.
/** * @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 } });
-
You need to make sure that the script returns a value. On the Script record page, on the Parameters tab, select a value from the Return Type list.
-
In SuiteFlow, create a workflow field. The field should be the 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).
The return value from the Workflow Action script can be stored in the Store Result In field.