Scheduled NetSuite Workflow that runs a SuiteScript

Here is a list of steps required to create a scheduled NetSuite workflow that runs a SuiteScript:

  1. Create a saved search
  2. Create a scheduled workflow that references the saved search
  3. Write, upload and deploy a “workflow script”
  4. Associate the workflow script with the workflow
  5. Test the workflow
  6. Release the workflow

Create a saved search: Your saved search and your workflow must reference the same record type. In this example, the record type is Customer.

Pic1

Create a scheduled workflow that references the saved search: Note that the record type is Customer and the “Saved Search Filter” is the saved search you just created.

Pic2

Write, upload and deploy a “workflow script”: Note that this script is executed once for each record returned by the saved search. The context for this script is the customer record returned by the search.

Pic3

As with any script, you need to upload your JavaScript file to the server and then create a script record.

Pic4

When you define the type, pick “Workflow Action.”

Pic5

You will be required to select an entry point in your script. In this example, the init() function in the namespace demo_workflow_script is the entry point.

Pic6

When you deploy the script, you need to associate it with the same record type as your saved search and your workflow. They all need to match!

Pic7

Associate the workflow script with the workflow: When making this association, it is done as an action. Here is where you add an action to your workflow.

Pic8

The action type will be your script.

Pic9

Test the workflow: You can test your script by editing the workflow and clicking “Execute Now.” Keep in mind that when testing this button only sends 20 records from your saved search to your script. Also, remember that when your workflow is in Test status, it will not run on the workflow’s schedule.

Pic10

Release the workflow: When you are satisfied that your workflow and script are correct, you need to edit your workflow and change the status to “Released.”

Pic11

Here is the code for the example SuiteScript in a form that can be easily copied:

var demo_workflow_script = {
init: function() {
// When this script executes, API calls will reference a customer record
var entity_id = nlapiGetFieldValue(“externalid”);
nlapiLogExecution(“DEBUG”, “demo_workflow_script”, “entity_id of current record: ” + entity_id);
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s