Marty Zigman - The NetSuite Expert

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

Prolecto Labs Accelerator Templates

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

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

About Marty Zigman

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

Biography • Website • X (Twitter) • Facebook • LinkedIn • YouTube

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

  1. Sinan Kazan says:

    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 ?

  2. Marty Zigman says:

    Hello Sinan,

    My instinct is that you need more fundamental Workflow Action Script concepts down. The key to understand how this works is that once you get into SuiteSript from the calling workflow, you can lookup the record that got you there to begin with. Once you have that record, you can then lookup anything else you need.

    Marty

  3. Jomon says:

    Can we Call a suitelet from a workflow action script??

  4. Marty Zigman says:

    Hello Jamon. Yes, once you are in the Workflow Action Script, you can then call out to other SuiteScripts including SuiteLets. The permissions can be tricky.

  5. Rosemol Joe says:

    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 ?

  6. Marty Zigman says:

    You can basically create two different workflow action scripts. One you call for create, the other for edit. The code can be built in such a way to centralize the functions.

    Marty

  7. Reddy says:

    Hi, thanks for the valuable information.

    Can we call workflow action script from any other script type?

  8. Marty Zigman says:

    Hello Reddy,

    Use a pattern that makes your code reusable. The best way to handle this is to have your function in a library. Then, you can call it from Workflows and other scripts.

  9. Rosemol J says:

    Can we trigger workflow when a record is updated via Suitelet ?

  10. Marty Zigman says:

    Yes, you should be able to. A SuiteLet is effectively a client program and thus all workflows and suitescripts fire if properly deployed.

  11. amala says:

    Hi Thank you for the Workflow .Could we do workflow action script on the Purchase order multilevel

  12. Marty Zigman says:

    There is no reason you would not be able to create a Workflow Action script on a purchase order. Once you are in SuiteScript, you can do whatever it is you need to do that is supported by that language and environment.

    Marty

  13. Aden Enzi says:

    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!

Leave a Reply

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