The workflow action script type enables NetSuite professionals to merge the SuiteScript and SuiteFlow worlds into one. When might this be useful, and how do we do this?

Introduction

In a previous article, we addressed the benefits and limitations of workflows. The limitations of workflows are important to consider, especially when developing a new automation of some kind. As a general rule, workflows should focus on basic automations. But sometimes life isn’t so simple—and NetSuite is prepared for that.

What Is a Workflow Action Script?

A workflow action script enables workflows to use scripting functionality.

Just like any other SuiteScript, a workflow action script is created with code and uploaded to NetSuite. Once you create the script, you can connect it to a workflow to extend functionality.

When to Use a Workflow Action Script

There are several reasons why you may find a workflow action script type to be helpful. One common use-case would be for an admin to attach a particular automation to their workflows. Having the flexibility to add scripting logic freely can be a significant advantage. There may be other reasons as well, but having this option is always a plus.

The onAction Entry Point

define([], function () {
    /**
     * @NApiVersion 2.1
     * @NScriptType WorkflowActionScript
     * @author Ben Rogol (SuiteRep)
     */
    const exports = {};


    function onAction(context) {

        // Perform automation here. For example:
        const recordObject = context.newRecord;

        recordObject.setValue({ fieldId: 'trandate', value: new Date() });
    }


    exports.onAction = onAction;
    return exports;
});

There is one primary function to take note of here—onAction. This is the function that your workflow will call. Within that function you can perform any logic you need to do. You may also want to consider separating that functionality into a library script so other SuiteScripts can access your logic in the future.

How to Connect Script to Workflow

Deploy script

The first thing to do is deploy the script. After uploading the script file to NetSuite, create a deployment record for the script. When creating the deployment, be sure to deploy it to the same record your workflow is deployed to. For example, if your workflow is running on a Sales Order, you will want to also deploy your workflow action script to Sales Orders.

Select the script in your workflow

If everything deploys correctly, you should now see the option to use your workflow action script as an action in your workflow.

Conclusion

Some of the most flexible and powerful automations can result from combining different areas NetSuite together. By combining the depth of scripting with the accessibility of workflows, we can create a truly unique user experience for clients. Let us know if you have any questions about the workflow action script type. And remember to subscribe to our email list to stay up to date with our latest blogs!

0
Would love your thoughts, please comment.x
()
x