Attaching JavaScripts to Widgets

For complex dynamic behaviors which cannot be obtained from rules,you can attach one or more scripts to widgets or OPI. The script grammar is JavaScript, but more than plain javascript, you can set PVs as input and change properties of widgets in the script. The script execution is triggered by input PVs. That means the change of PV value will trigger the execution of script. In script, the value or severity of the input PVs are accessible.

Besides, all Java APIs are accessible in script by importing the package of java.lang.

Steps to attach scripts to a widget:

  1. Select Scripts property in property sheet view.
  2. In Attach Scripts Dialog, you can add more than one script. For each script, you can specify more than one PV as the input.

    Script Configuration Dialog

  3. Run OPI to see the result.

JavaScript Grammar Tutorial

There are lots of free JavaScript Tutorial available from Internet, for example w3schools JS Tutorial. You only need to read the JavaScript grammar part. The other parts are not appliable in BOY.

JavaScript Objects

Please notice that the JavaScript in BOY is not executed in an environment of browser, so the objects such as document and methods such as alert(), confirm() are not available here, but the JavaScript Objects such as Date, Array, Math are still available. This is an example showing the current datetime on a Label widget.

widgetController.setPropertyValue("text", new Date().toString());