Business Condition: Evaluate JavaScript

In addition to the standard business rule operations, more complex functions can be carried out using JavaScript and the Scripting API. This condition enables you to use the same STEP Public Java API methods that are available in the Execute JavaScript business action operation.

Conditions contain tests, and the JavaScript should only evaluate to true or false.

  • The Boolean value 'true' must be returned for the condition to evaluate to true.
  • Any returned value other than the Boolean value 'true' makes the condition evaluate to false. A false condition can display a user-facing message by either returning a string or a message object (localized).

Important: Business conditions are optimized for determining the true / false result of read-only scenarios. Although it is technically possible to write business conditions to change data, doing so can result in unpredictable errors and should therefore not be attempted. To change data effectively, use a business action and the Execute JavaScript operation. For more information, refer to the Execute JavaScript section of the Business Rules documentation here.

Using JavaScript in business rules can include:

  • Evaluate JavaScript operation is used for conditions. For more information about business rule conditions, refer to Business Conditions here.
  • JavaScript Binds for both action. condition. and function operations. Binds provide access to the data being worked on. For more information, refer to JavaScript Binds in the Resource Materials online help here.
  • Business Libraries is a set of JavaScript functions that can be reused in multiple business rules. For more information, refer to Business Libraries here.
  • Scripting API documentation is accessed via the Technical Documentation, at [system]/sdk or from the Start Page.

Prerequisites

Before using this business condition:

  1. Understand the implications of using JavaScript as defined in the Java vs. JavaScript topic in the Resource Materials online help here.
  2. Understand the considerations that should be taken as defined in the JavaScript Considerations topic in the Resource Materials online help here.
  3. Create a business rule as defined in the Creating a Business Rule, Function, or Library topic here.
  4. Edit the business rule to configure the operation as defined in Editing a Business Rule or Function topic here.

Configuration

  1. On the Edit Operation dialog, select Evaluate JavaScript from the dropdown.
  1. For the Binds parameter, create binds needed for the JavaScript code as described in the Adding a Bind topic in the Resource Materials online help here.
  1. For the Messages parameter, create messages needed for the JavaScript code as follows:
  • Click the Edit button () to display the Edit Messages dialog.

  • Click the Add message button () to create a new message entry.
  • Click the Remove button () to delete a message entry.
  • For the Variables text box, type a label for the variable.
  • For the Message text box, type the message.
  • When necessary, open the Translations flipper and provide the data required. A localized message option is available in both JavaScript business actions and conditions. For more information, refer to the Localized Messages for JavaScript Business Rules documentation here.
  • Click OK to save the messages to the operation.
  1. For the JavaScript parameter, add the JavaScript code.
  2. Click the Save button to add the operation to the business rule editor.