Client Script Library Reference

Web HMI provides some useful client script utilities for developers who wish to have more control over application behavior. The following objects and functions are available to use:

Authentication

OAS.authenticate(string, string)
Pass in a username and password to perform a server authentication call. Once complete, all tag data requested from the server will occur within that user’s context and bound to that user’s permissions. If the user does not have access to a given tag, no value will be returned. The authentication is performed asynchronously, and will take effect when either the call completes successfully or fails. Upon completion or failure, the OAS.token value will be updated. Upon failure, the OAS.token will be set to “AUTH FAILURE” when there is a communications issue, but will be set to a GUID token for all other results. Note: the user identity and permissions are managed within the Open Automation Software Server:

Reading Tag Values

OAS.get_value(string)
Pass in a tag as a string to get the current value for that tag:

Writing Tag Values

OAS.set_value(string, string)
Pass in a tag as a string, and a new value and that value will be set on the server:

Toggle Polling

OAS.toggle_refresh(bool)
Temporarily disable or re-enable server polling for new tag values. If no parameters are passed in, polling will toggle, turning off when currently active, or back on when suspended. To explicitly start or stop polling, pass in a boolean true or false, respectively:

Initialize Script Engine

OAS.init()
Reinitialize the client script engine and begin polling. Use this function if there is ever a need to dynamically update any configuration settings, for example if you ever choose to programmatically point to a different serverURL, add tags to the watch_tags array, or add elements to the screen to be parsed and managed by Web HMI behaviors:

Client Object Structure

The client script library caches tag data in an object structure that can always be inspected in your custom code. This is particularly useful for debugging data being sent by the server, and for determining Tag data quality in your own script. You can access this object store at any time:


var tags = OAS.tags;

Below is the general structure of the tags object. Each tag is a node in the object containing a props structure that tracks every OAS Tag property being monitored. For example, if you are tracking Pump.Value, there will be a Value property in the props object. If you are tracking both the Value and the Description of each tag, you will find one object for each.

For example, using this prototype you would check the data quality of the Pump.Value using the following code: