Trigger Client Scripts from a Workflow

Client script functions can be triggered by any Workflow Action scripts that support client-based events (e.g., Before User Edit, After Field Edit, etc.). These functions should be placed in the Custom Formula section of the workflow action.

Here’s an example that demonstrates this process. It requires basic knowledge of SuiteScript and Workflows.

Solution:

1. Create a JavaScript file with the following code:

function sayHello(s) {

  alert(‘Hello ‘ + s); 

  // Return true or false to allow or prevent the workflow action from executing.

  // If this line is omitted, the workflow will treat the function as false, 

  // preventing Workflow Actions like “Set Field Value” from executing.

  return true;

}

Note: The function will be called by the workflow in Step 5.4.

2. Navigate to **Customization > Scripting > Scripts > New**.

3. Click the “+” icon next to the Script File Popup List.

4. Select the JavaScript file in the File Popup Window, then click Save.

5. Under the **Deployments** tab, add the record to which the script and workflow will apply (e.g., Customer record), then click Save.

6. Navigate to **Customization > Workflows > Workflow > New**.

Basic Information:

– **Name**: Enter a name (e.g., Customer Workflow).

– **Record Type**: Select Customer.

– **Sub Types**: Select Customer.

– **Execute as Admin**: Check this option.

– **Release Status**: Select Released.

Event Definition:

– Check **On Create.

– Check **On View or Update.

7. Click Save, then click **State 1.

8. In the bottom right corner, click New Action and choose Set Field Value.

Basic Information:

– Trigger On: Select Before User Edit.

– Event Types: Select Create.

– Context: Select User Interface.

– Triggering Client Fields**: Select Memo.

Condition:

– Select Formula.

– In the Formula field, enter `sayHello(nlapiGetFieldValue(‘companyname’))`.

Parameters:

– Field: Select Account.

9. Click Save.

Leave a comment

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