NetSuite Workflow Action Script

How to Create NetSuite Workflow Action Script

A SuiteScript is a very popular NetSuite platform used for customizing and automating your business processes completely. It has been built on high-level and multi-paradigm JavaScript. The NetSuite Workflow Action Script is one such type of  SuiteScript

The NetSuite Workflow Action Script permits you to add more actions as compared to the point-and-click SuiteFlows. Using these scripts, you can easily execute specific with the help of SuiteScript APIs that are currently available in the market. For instance, creating records and manipulating sub-lists. 

Creating and direct to a record using NetSuite Workflow Action Script

Concerning NetSuite Workflows, the creation and redirecting to a record becomes much easier. However, there are some restrictions on it. For instance, a transaction cannot be created using Workflow Manager, which is a high-scale host that facilitates hassle-free running as well as managing different workflows. Another example can be the inability to create a Custom Record for parent-child relation using NetSuite Workflows. 

But, these restrictions can be easily overcome with the help of SuiteScript. The well-built NetSuite Workflow Action Scripts are used for this purpose. 

How to create a NetSuite Script?

Let’s understand how to create a NetSuite Workflow for creating and directing to a record using NetSuite Workflow Action Scripts. It is not that difficult a task, you just need to follow a few simple steps for it.

  • Visit the “Customization” tab located on the workflow action page
  • You will get a drop-down menu, in that, select the “Scripting” option
  • Again, you will get a pull-down menu, in that, pick “Scripts” option
  • Mark the “New” tab after getting the new drop-drop menu

NetSuite Workflow Action Scripts guide

Upload File

Upload your file

Choose Workflow Action from the script types

Choose Workflow Action from the script types

Type in your script name

type in your script name

 

Make the script deployment – check the all roles checkbox and execute as Administrator – keep the status to testing

make the script deployment

In simple format: Customization -> Scripting -> Scripts -> New

  • Upload the sample script
  • Enter the name in the specified field
  • Mark the “List/Record” option under the Parameters section
  • Choose your preferred “Record Type”, for instance, Custom Record
  • Click on the “Save” tab for storing these updates
  • Later, click on the “Deploy Script” tab 
  • Also, choose the record type for which this workflow intended
  • Retain the status “Testing” unchanged
  • Click on the “Save” tab to store all the updates

The example for a typical NetSuite Workflow Action Script:

/**

*

@NApiVersion 2.x

 * @NScriptType WorkflowActionScript

 * @NModuleScope public

 *

 * Author: LEX

define([‘N/record’, ‘N/runtime’],

     function(record, runtime) {

        function wfCreateRfQ(scriptContext) {             

            var currentRecord = scriptContext.newRecord;

            var title = currentRecord.getValue(“title”);

            var recordType = “customrecord_test_record”;

var objRecord = record.create({

type: recordType,

            isDynamic: true

});

            objRecord.setValue({

                    fieldId: “name”,

                    value: title

                });

            objRecord.setValue({

                    fieldId: “custrecord_lcc_text”,

                    value: “Test from Workflow”

            });

            var recordId = objRecord.save({

                enableSourcing: true,

        ignoreMandatoryFields: true

            });

            return recordId;

        }

        return {

            onAction : wfCreateRfQ

        }

})

How to create a Custom Field?

It becomes highly important since the ID of a newly created custom record will be stored in it. The record can be stored in two different ways, by creating, a workflow field or a custom field. The first option can be chosen when you are not intending to store the record for future use or user access. On the other hand, the second option can be selected when you are well-aware of the record type for which you are deploying this new workflow.

Make script parameter for input

make script parameter for input

Let’s study this process by trying to create “Task” – a workflow for CRM step-by-step:

  • Click on “Customization” tab available on the workflow action page
  • Select the “Lists, Records & Fields” from the drop-down menu
  • You will get a pull-down list, in that, pick “CRM” fields

In simple words: Customization -> Lists, Records & Fields -> CRM fields

  • Enter the name in the specified tab, for instance, “Associated Record
  • Under type choose “List/Record” option and you will get a drop-down menu
  • Select the “Custom Record” in that menu
  • Under the section, named, “Applies To”, click on the “Task” option

How to create a Workflow?

  • On the workflow action page, click on “Customization” tab and you will get a drop-down menu
  • Select the “Workflow” option available on that list and then select “New” from the listed options
  • Enter the name in the specified tab and deploy it your preferred record type, for example, “Task

Goto Customization

new Workflow

Workflow setup1

Workflow setup1.png

 

Workflow setup

Workflow setup2

Click on add button

Click on add button

Choose a label for your button

Choose a label for your button

Create a transition from State 1 to State 2 on the button you previously created.

Create a transition from State 1 to State 2

Now choose an action you deployed. Now choose an action you deployed. on state 2

Now choose an action you deployed. Now choose an action you deployed. on state 2

Sample Data For Demo Record

Sample Data For Demo Record

Set an action on state 3

Set an action on state 3

 

In simple words: Customization -> Workflow -> New

  • You will get a new page titled “Workflow Summary
  • Mark the option “On View or Update
  • Select “Before Record Load” under Trigger Type
  • Click on the tab “New Action” and select the option “Add Button
  • Enter your preferred label, for example, “Create Record” 
  • Click on the tab “Save” to save the details
  • Then, click on the button “New State”  
  • Insert a transition between State 1 & 2
  • You will get a pop-up named “Transition
  • Click on the “Execute” button then choose the button that you have already created  
  • On State 2 tab, click on the “New Action” tab
  • Then, choose the workflow action you have deployed already (It must display the word “(Custom)” with its name. For Instance, LCC WFA Script Test (Custom)
  • Mark the custom field on “Store Result In” in the pop-up window
  • Insert a new state – State 3
  • Then, insert a transition between State 2 & 3
  • Click on the tab “New Action” on State 3
  • Then, move to “Go to Record
  • In the pop-up window, switch the “Trigger On” to the “Entry
  • Go to the Parameters section of the “Go to Record
  • There, mark “Custom Record” under the “Record Type
  • Also, on the “Field” tab, select custom field i.e. Associated Record
  • Mark on the “Open in Edit Mode
  • Click on the button “Save” to store the updates

How to test a Workflow?

Set trigger on “Entry
Record type “Demo record“(Your custom record)

test a Workflow

You easily deployed the NetSuite Workflow Action Script with the help of the above-mentioned steps. It means you executed the script, created the custom field, and also configured the workflow. Now, it’s time to test the workflow and view the output.

Let’s follow the below steps to test the “Task” workflow:

  • First, view any of the “Task” records
  • Click on the button “Test Record
  • You will notice that the record is redirected to the “Custom Record” that has been created by the NetSuite Workflow Action Script

If you have any concerned about NetSuite Workflow Action Script then talk to our NetSuite developer

or Call – +61 480 016 233

Posts created 23

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top