Localized Messages for JavaScript Business Rules

Messages in business rules can be translated and used in:

Note: This option uses locales. It is not context-dependent. Contact Stibo Systems to display additional language locales on your Web UI or workbench.

Return Statement with Conditions

The return statement is not available in a business action, instead, in conditions, it is used to indicate whether the condition is true or false. When Boolean true is returned, the condition evaluates to true. Any other return value will make the condition evaluate to false.

The return from a condition can be a message and can also be reported in a Data Issues Report, on a mandatory object (via the Mandatory Bind), or on a read only object (via the Read Only Bind), which can each take a localized message.

To have a message displayed to the user when a condition evaluates to false, you can:

  • return a simple String, as shown in the following example:

    return "Object is not ready";
  • return a translatable error message object, which can display the message in a language matching the UI locale. Refer to the following example.

Example

Use the following steps to configure a business condition that uses the Data Issues Report to display a localized message.

  1. On an existing 'Evaluate JavaScript' operation, click the Edit button () in the Messages parameter to display the 'Edit messages' dialog. For more information, refer to the Editing a Business Rule or Function topic.

  2. Click the Add message button ():

    • Add a variable name and the message text. A variable message can include the name of the business rule or any other data that would be helpful in resolving the problem reported by the message.

    • Open the Translations flipper (), click the Add translation button (), and add the translated text. Multiple translations can be added. Do not translate variable tags.

  3. Click OK to close the 'Edit messages' dialog and display the number of translations added.

  4. On the Edit Operation dialog, for the JavaScript parameter, add JavaScript code with a 'return' statement to display the message.

  5. If you created a translation, test the results by logging in to the locale that matches the language for the message. The screenshot below shows where to select a workbench locale, an on-prem local, and a SaaS locale.

    For workbench, either test the business rule (defined in the Testing a Business Rule topic) or run a workflow that uses the business rule to display the translated message.

    For the Web UI, trigger the business rule or run a workflow that uses the business rule to display the translated message.

Throw Statement with Actions and Conditions

You can deliberately throw exceptions from both actions and conditions if an error state is encountered. The exception message can be a translatable message object.

Example

The following shows how to configure a business action to display a localized message.

  1. On an existing 'Execute JavaScript' operation, click the Edit button () in the Messages parameter to display the 'Edit messages' dialog. For more information, refer to the Editing a Business Rule or Function topic.

  2. Click the Add message button () and add a variable name and the message text.

    A variable message can include the name of the business rule or any other data that would be helpful in resolving the problem reported by the message.

    A variable tag within the message text is optional. In this example, the tag is {size} and will return the value of the attribute from the bound product.

  3. Open the Translations flipper ().

  4. Click the Add translation button () to add the translated text. Multiple translations can be added. Do not translate variable tags.

  5. Click OK to close the 'Edit messages' dialog.

  6. On the Edit Operation dialog, for the JavaScript parameter, add JavaScript code with a 'throw' statement to display the message.

  7. If you created a translation, test the results by logging in to the locale that matches the language for the message. The screenshot below shows where to select a workbench locale, an on-prem local, and a SaaS locale.

    For the Web UI, trigger the business rule or run a workflow that uses the business rule to display the translated message.

    For workbench, either test the business rule (shown below, also refer to the Testing a Business Rule topic) or run a workflow that uses the business rule to display the translated message.