SOTI Snap Agent JavaScript API Support

As of version 2.2.0, the SOTI Snap agent supports the use of well-defined JavaScript APIs to interact with SOTI Snap app widgets and environment variables while the apps are running on Snap agent.

You can introduce dynamic behavior to your apps by adding a Run JavaScript action on any widgets that support events and actions.

JavaScript Engine

As of SOTI Snap 2.2.0, it is recommended that you make use of SOTI Snap supported JavaScript APIs. Use this reference guide for a list of available SOTI Snap specific JavaScript APIs and guidance on how to use them.

Prior to 2.2.0, app developers were limited to using native JavaScript DOM APIs or jQuery-based APIs to interact with SOTI Snap widgets. You can still use these APIs; however, the usage of these APIs may not align well with the overall functioning of the app. Wherever possible, we recommend that you replace them with SOTI Snap specific JavaScript APIs.

Features and syntax introduced in ECMAScript 2015 (ES6) are not supported.

JavaScript Editor - Intelligent Code Completion

SOTI Snap supports intelligent code completion making it easy to quickly build and add SOTI Snap JavaScript APIs.

Snap JavaScript Editor

The JavaScript editor in the SOTI Snap console also provides a convenient way to refer to an app's environment variables and app widgets.

Snap JavaScript Editor - Variable

 

Snap JavaScript Editor - App Fields

Working with JavaScript Modules

Example:

Working with App Widgets Object (Snap.widgets) And Environment Variables Object (Snap.variables)

Snap.variables.setvalue("var-price", Snap.widgets.textbox.getValue("unitPrice"));
//get the value of he textbox “unitPrice” and set in variable (Var-price)
Snap.variables.setvalue("var-items", Snap.widgets.textbox.getValue("itemsSold"));
//get the value of the textbox “itemsSold” and set in variable (Var-items);
Snap.variables.setvalue("var-total", var-items * var-price);
// Set value of variable "var-total" by multiplying with var-price with var-items
Snap.widgets.label.setDisplayText ("totalPrice",Snap.variables.getvalue("var-total");
//set the text for the label "totalPrice"

Example:

Working with Navigation Object (Snap.navigation)

Snap.navigation.navigateTo("page-id");
// navigate to any page or screen by providing its ID