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.

Before you use this script, make sure you’ve done the following:

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

General Notices