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 Business Action: Execute JavaScript section of the Business Rules documentation.

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.
  • 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 documentation.
  • Business Libraries is a set of JavaScript functions that can be reused in multiple business rules. For more information, refer to Business Libraries.
  • Scripting API documentation is accessed via the Technical Documentation accessible at [system]/sdk or from the Resources section of the system's 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 documentation.
  2. Understand the considerations that should be taken as defined in the JavaScript Considerations topic in the Resource Materials online help documentation.
  3. Create a business rule as defined in the Creating a Business Rule, Function, or Library topic.
  4. Edit the business rule to configure the operation as defined in Editing a Business Rule or Function topic.

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 documentation.
  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.
  • 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.