Workflow Action Script

Hi there,

In this post we will learn about  workflow action script.
Workflow in Netsuite as very useful but they lack out of box functionalities.You can check all limitations here.
When workflow actions script was released , sublist was not available for workflows, In new release netsuite allowed sublist access in workflow but workflow action does much more task than just accessing sublist.
Example: Getting data from record which do not have join with current record, or going to many level up in hierarchy of records, sending email with complex structure etc.

Once workflow action script gets created in netsuite, in workflow you will see this newly created action
script as custom action. Please remember if you create Workflow Action script for transaction records
then  this custom script will show only in workflow for transaction.

Workflow Action script allows to return value and stored in workflow for further use. In SuiteFlow, create a
workflow field. The field should be of the same type as the return parameter of 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

Entry Point:

Workflow use "onAction" as entry point for script.

Steps to create Workflow Action Script:
Step 1: Create file in .js format and upload to file cabinet using Customization>Scripting>Scripts>new
Workflow Action Script




Step 2: Click on "Create Script Record" button

Step 3: Enter Name, id and other details


Step 4:  Create parameter if return field is needed.
Step 5: Click on Save and Deploy



Step 6: In workflow , select custom action


Step 7: Create workflow field in Workflow


Step 8: Select return under workflow action


Step 9: Save .


Code: return true if item matches
/**
 * @NApiVersion 2.x
 * @NScriptType WorkflowActionScript
 */
define([], function() {
    function ngAction(scriptContext){
       
        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 item = newRecord.getSublistValue({
                sublistId: 'item',
                fieldId: 'item',
                line: i
            });
           
            if (item === 1121){
                return true;
            }
        }
       
        return false;
    }
    return {
        onAction: ngAction
    }
});

If you have any query, please comment below.


Thanks
Netsuite Guru

Download Netsuite Guru Android App
Follow Me on Linkedin
Our FB Page

Comments

  1. Can a workflow action script be used to edit the value of a record in view mode?

    ReplyDelete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin