Testing a Business Rule

Typically, after creating any business rule, it is important to test that it performs as expected.

For an overview of the decision points involved in running a business rule, refer to the chart in the Running a Business Rule topic here.

Important: Business rules using context-specific JavaScript binds cannot be tested using this method. Therefore, JavaScript that uses the import change info or approve context binds cannot be tested. Similarly, business actions where the Execute JavaScript function is used to create parametrized business rules cannot be tested.

Monitor Business Rules

Using the BusinessRule.Warning.Threshold configuration property in the sharedconfig.properties file, allows you to specify a threshold in milliseconds for business action execution. If it takes longer to execute or test a given business action, a warning is posted in the main STEP log file available from the STEP System Administrator button on the Start Page. For information on the log, refer to the Logs topic in the Administration Portal documentation here.

Test & Time Business Rule Dialog

Choose one of the following ways to display the Test & Time Business Rule dialog:

  • In System Setup, expand the business rules node, select the business rule to test, display the right-click menu, and click Test Business Rule.

  • While displaying the Edit Operation dialog for a JavaScript business rule, click the Test JavaScript button.

Click the Test JavaScript button to test modifications made to the JavaScript. If the modifications should be retained, click Save. If the modifications should be rolled back, click Cancel.

Perform Test & Time on a Business Rule

The Test & Time Business Rule dialog includes standard parameters for actions, conditions, and functions. In addition to the standard parameters, testing action business rules includes the 'Rollback changes after test' parameter.

In addition to the standard parameters, testing function business rules includes a Parameters section that shows each of the input parameters defined in the business function.

After displaying the dialog, supply the following information to test a business rule.

  1. For actions or conditions, in the Test Object parameter, click the ellipsis button () to display the Select Test Object dialog. Use the Browse or Search tab to identify and select the object used to test the business rule.

Note: The selected object must be of an object type that is valid for the business rule.

  1. For functions only, in the Parameters section, click the ellipsis button () to display the appropriate selection dialog required for the Input Parameters available in the function. Use the Browse or Search tab to identify and select each input object for testing.
  2. For actions only, the Rollback changes after test checkbox is available. When checked, any changes caused by the action are rolled back after the action has been executed.
  3. The Attempt Stop After: __ Seconds is checked by default, with the numeric value of ten in the editable field. When checked, if the business rule test does not complete within the number of seconds specified, it is terminated, if possible. This prevents an infinite loop or other unintended long running business rules. The maximum value for the field is 600 seconds. If the business rule test exceeds the limit, the error is displayed: 'Javascript terminated as its execution time exceeded timeout of X seconds,' where the 'X' is the number of seconds in the field.
  4. The Execute in Approved Workspace is unchecked by default and the test is performed in the Main Workspace. When checked, the action is performed on the selected object in the Approved Workspace.

Since business functions cannot change data in any workspace, this parameter is not available for business functions. Testing a business function is performed in the current workspace.

  1. Click the Test button.

Test & Time Business Rule Results

The following parameter values are supplied when the test is complete.

  • Timing - Displays the time taken to execute the business rule on the selected node.
  • Status - Displays OK (text succeeded), Not Applicable (object type tested is not valid), or Error as the outcome of the business rule test.
  • Result - For conditions only, displays the result of the test (true or false) and any localized messages. For more information, refer to the Localized Messages for JavaScript Business Rules topic here.
  • Error Details - Displays additional information on an error result, including the stacktrace when available.
  • Log - Displays the log message for debug and/or testing purpose. In JavaScript, use Logger in the code to log a message, as described in the Logger Bind topic in the Resource Materials online help here.

Testing Outcome Examples

  • OK - This status is displayed when the test is executed successfully. In the following example, a function that concatenates two input values is tested. The outcome of the function is displayed in the Result parameter. For another testing scenario including a function, refer to the Calling a Business Function from a JavaScript Business Rule topic here.

Testing the following business condition includes the outcome of the condition and the localized message in the Result parameter. A Logger message is displayed in the Log parameter.

  • Non Applicable - This status is displayed when the test object does not match the Valid Object Types on the business rule, as illustrated in the action business rule test image below.

  • Error - This status is displayed when the business rule has invalid methods, syntax, or function. For the following condition test, the Error Details parameter includes stacktrace and troubleshooting information.

The following business rule has a problem in the JavaScript code as indicated by the row number in the error details parameter.