Creating and Using Workflow Action Scripts

You define a workflow action script like you would any other SuiteScript type: go to Customization > Scripting > Scripts > New.

Using a workflow action script, you can create generic Custom Action that are available to all record types. Do this by selecting All Records in the Applies To dropdown list on the Script Deployment page.

An example of the Deployments subtab in a script deployment record.

These custom actions then become available to all workflows, regardless of the underlying record type of the workflow. Through generic custom actions you can (for example) create a parameterized, generic action to set sales rep values. You can then set the parameters from within a workflow and invoke the generic “Set Sales Rep (Custom)” action, which will contain values specific to that workflow.

Be aware that if you set a workflow action script to deploy to All Records, and then you try to specify another record type on the script's Script Deployment page, you will receive an error. Also note that if you set the deployment of a workflow action script to All Records, the script will appear in the palette of actions (labeled as custom ) for all workflows.

You can create parameters for a workflow definition in the customization details in the workflow manager.

You can also set the type of the value returned by a workflow action script. You make this choice on the Parameters subtab on the script record. If there are fields of the same type defined in the workflow (or workflow state), you can configure this value to be saved as the value of a specified field.

Additional Example

The following is a custom action workflow action script that sets the sales rep on the record in the workflow.

            /**
 * @NApiVersion 2.1
 */

function onAction (scriptContext) {
  const newRecord = scriptContext.newRecord;
  const myScript = runtime.getCurrentScript();
  const scriptParamSalesRep = myScript.getParameter({
    name: 'custscript_salesrep'
  });
  newRecord.setValue({
    fieldId: 'salesrep',
    value: scriptParamSalesRep
  });
} 

          

Notice there is no use of the record type and record id parameters (they are still sent, however); instead, the scriptContext is used to return all necessary data for the record currently in the workflow.

Also note that when executing workflow action scripts, the current record context is workflow. See runtime.executionContext for details on returning context information about what triggered the current script.

Related Topics

General Notices