Creating and Using Workflow Action Scripts

You set up a workflow action script like any other SuiteScript type: go to Customization > Scripting > Scripts > New.

With a workflow action script, you can create generic Custom Actions available for all record types. Choose All Records in the Applies To dropdown on the Script Deployment page.

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

These custom actions will then show up in all workflows, no matter the record type. For example, you can build a generic, parameterized action to set sales rep values. Then set the parameters inside the workflow and run the “Set Sales Rep (Custom)” action to use values specific to that workflow.

If you deploy a workflow action script to All Records, you can’t also pick another record type—otherwise, you’ll get an error. When set to All Records, the script appears as a custom action in all workflows.

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

You can also set the return value type for a workflow action script on the Parameters subtab of the script record. If your workflow (or workflow state) has fields of the same type, you can set this value to be saved to a specific 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 that you don’t need to use the record type or record ID parameters (they’re still sent, though); scriptContext gives you everything you need for the current record in the workflow.

Also, when running workflow action scripts, the current record context is workflow. See runtime.executionContext for more about what triggered the script.

Related Topics

General Notices