Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

How To: Create Custom NetSuite Workflow action with SuiteScript

NetSuite Technical

Tags: , , , , ,

This article is relevant if you need to create a custom NetSuite workflow action script.

Background

In previous articles, I discussed the power of our Content Rendering Engine to help drive branded output (email, PDF, or other) in NetSuite.  That application can be driven from workflows allowing NetSuite Administrators full control over the timing of custom content generation.  In our example use case, we will be generating a custom NetSuite Item Fulfillment (ship confirmation) using our provided standard template.

Key Steps to Creating the Custom NetSuite Workflow Action

Here are the key steps you need to follow to get your Workflow to execute SuiteScript.  See associated images to help illustrate what is needed.

  1. Record Orientation: Consider that Workflows work with records and that you will be passed the record ID that needs processing.
  2. Record ID: Setup your SuiteScript to discover the record ID and then perform your work.
  3. Script Definition: Create your SuiteScript definition record as type Workflow.  Ideally, use script parameters that allow you to define more input data for your SuiteScript to process more complex logic.
  4. Script Deployment: Deploy your Workflow against the record you care about.  This should be the same record type that your Workflow will be processing.  Be sure to set deployment parameters to allow full (all roles) audience visibility, debugging and other switches.  You will not set the script parameters here as you typically would for a SuiteScript.  These will be set in the Workflow definition.
  5. Workflow Definition: Configure your workflow and test.

Sample NetSuite Workflow SuiteScript

The following SuiteScript can be copied and modified to help you activate your Workflow Action Script:
function creProfileWorkFlowAction() {
	var func = "creProfileWorkFlowAction ";
	nlapiLogExecution("DEBUG", func + "Starting ", "");

	//get data on the record being processed (depends on the deployment)
	var rec = nlapiGetNewRecord();
	rec_id = rec.getId();	//the key we need to drive the Content Rendering Engine
	rec_type = rec.getRecordType();  // if needed, we can discriminate; but no need in this model

	//get the script deployment parameter to learn which Content Rendering Engine Profile is in play
	var context = nlapiGetContext();
	var profileid = context.getSetting('SCRIPT', 'custscript_cre_wf_profile_id');

	//output some diagnostics
	nlapiLogExecution("DEBUG", "rec_type", rec_type);
	nlapiLogExecution("DEBUG", "rec_id", rec_id);
	nlapiLogExecution("DEBUG", "profileid", profileid);

	//let's go to work
	try {
	  if (!profileid){
	  	 throw nlapiCreateError(func, "Must supply a CRE Profile ID from Script Parameters");
	  };

	  //the actual work
	  var creProfile = new CREProfile(profileid);
	  creProfile.Translate(rec_id);
	  return creProfile.Execute();

	 } catch (e) {
	      if (e instanceof nlobjError) {
	          nlapiLogExecution("ERROR", func, e.getCode() + " : " + e.getDetails());
	      } else {
	          nlapiLogExecution("ERROR", func, e.message);
	      }
	      throw nlapiCreateError(func, e);
	  }
	nlapiLogExecution("DEBUG", func + " End ", "");
};

Script and Workflow Definitions

I have attached screen shots with annotation to help you see the setup. Click each link from left to right and top to bottom.

Enhance your NetSuite Account

One of the things my team and I love about the NetSuite system is the platform.  We can address concerns and invent solutions.  If you would like expert help to enhance your NetSuite account, contact us so we can setup a conversation.

Marty Zigman LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

14 thoughts on “How To: Create Custom NetSuite Workflow action with SuiteScript

  1. Hi , Thank you for your code example.

    I need to write a workflowscript which will collect workflow data and send mail .

    I need to take customer information in workflow for each customer. I dont know how to take customer information in workflow .

    how to send any record type to workflow as a parameter and how to collect that record type’s data in workflow . this is my main problem. Do you have any advice for me ?

    Reply
  2. Hi Marty,

    Suppose we’ve given two event types for the workflow. Create and Edit. In workflow action script, can we get this event type ? We don’t have a ‘type’ parameter passed here, right ?

    Reply
  3. Action Script will return “Audience not found error” when fired from online orders (Suite Commerce website). Is there a way to NOT specify the audience? Not choosing Audience will have the script fire under only the creator!

    Reply

Leave a Reply

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