Use nlapiTriggerWorkflow to Trigger a Transition Based on the Click of a Button

Use the nlapiTriggerWorkflow SuiteScript API to trigger a Workflow that is currently running on a record.

Solution

Create WorkFlow
Navigate to Customization > Workflow > Workflows > New
Basic Information:
Name: Enter Customer – nlapiTriggerWorkFlow
Record Type: Select Customer
Sub Types: Select Customer
Execute As Admin: Enter Checkmark
Release Status: Select Released
Initiation: Select Event Based
Event Definition:
On Create: Enter Checkmark
Trigger Type: Select Before Record Load
Click Save
Click State 1
Bottom right corner: Click New Action
Click Add Button
Basic Information:
Trigger On: Select Before Record Load
Label: Enter Go To State 2
Click New State button
Click State 2
Basic Information:
Do Not Exit WorkFlow: Enter Checkmark
Click State 1
Transitions:
Click New Transitions
To: Select State 2
Execute on Button: Select Go To State 2
Click Save

Trigger the Workflow when a new Customer Record is created
Navigate to Customization > Scripting > Script Debugger
New Script: Add below code

nlapiTriggerWorkflow(‘customer’, customer_id , ‘customworkflow_cust_nlapitriggerwf’, ‘workflowaction_go_to_state_2’);

Note: Replace customer_id with the Internal ID of the customer that was created. Also, If the Workflow is in a State that requires the click of a button to trigger a Transition, we can add the button ID on the parameters and this API will simulate the button click.

Click Debug Script
Click Continue Icon

Leave a comment

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