Here is a list of steps required to create a scheduled NetSuite workflow that runs a SuiteScript:
- Create a saved search
- Create a scheduled workflow that references the saved search
- Write, upload and deploy a “workflow script”
- Associate the workflow script with the workflow
- Test the workflow
- 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.
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.
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.
When you define the type, pick “Workflow Action.”
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.
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!
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.
The action type will be your script.
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.
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.”
Here is the code for the example SuiteScript in a form that can be easily copied: