JavaScript Considerations

JavaScript is a powerful tool that allows an extensive range of functionality that may be applied to manage and maintain STEP data. The following considerations should be observed to ensure the best use of this tool.

  • Variables: Although the Rhino engine used for executing JavaScript is reinitialized prior to the execution of each JavaScript plugin script fragment, it is considered recommended practice to declare all script variables using the “var” keyword.
  • Code Reuse: If you plan to construct more than just a few JavaScript-based business rules, business libraries should be used to hold common functions. If libraries are not used, it will be very hard to maintain the business rules as time goes on.
  • Error Handling: While most of the simple scripts shown as examples do not include error handling, for scripts to be run on a production system, error handling is essential. Common cases that should be handled include attributes that do not exist, or an attribute that does exist but has no value. Both of these cases would return an exception error. For more information, refer to the JavaScript Exception Handling topic here.
  • Parallel Streams: Parallel streams are forbidden in STEP. This is because of the code complexity involved. It can be difficult for customers to control and analyze resources when looking into, e.g., performance problems. Such coding, and any associated troubleshooting efforts, are not supported by the Stibo Systems R&D team
  • Java vs. JavaScript: When writing JavaScript Business Rules it is important to understand that the public Scripting API is a Java API. Thus all returned objects will be Java objects, not JavaScript objects. For more information, refer to the Java vs. JavaScript topic here.