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:

  1. 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.

  2. 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.

  3. 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:

  1. 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
            }
        }); 
    
                  
  2. Make sure that the script returns a value. You can specify this on the Parameters tab of the Script record page.

  3. In SuiteFlow, create a workflow field. The field should be the of the same type as the return parameter of the Workflow Action script.

    A screenshot showing the Type field highlighted.
  4. Within a state, add the custom action (this is the Workflow Action script).

    Screenshot of the custom action options.

    The return value from the Workflow Action script can be stored in the Store Result In field.

    A screenshot of the Workflow Action script being set to be stored in Return Value (Workflow) field.

Related Topics

Workflow Samples
Lead Nurturing Workflow
Lead that Did Not Convert to Customer Within Three Days
Estimate Approval Routing Workflow
Welcome Email Sent to Customers Three Days After First Order Workflow
Custom Action
Creating and Using Workflow Action Scripts

General Notices