HELP!

Scripting

Scripting (aka coding) is the use of computer language commands to implement an algorithm to manipulate data using a scripting language such as JavaScript. As well as fully supporting the JavaScript language, Viabl.ai offers low-code (menu driven) alternative scripting method called XpertScript which removes the need to learn a computer language.

Inappropriate use of Scripting

Although scripting allows conditional commands (such as "IF ELSE THEN") to be used, the developer should avoid coding "Business Logic" inside scripts (JavaScript or XpertScript) but should instead utilise Viabl.ai Platform's formal Knowledge Acquisition features. This would ensure Knowledge transparency and enables effective capture, validation and maintenance of the Business Logic.

Unassigned Object Errors

If an Unassigned (Empty/Blank) Object is encountered whilst executing a Script line that is expecting the Object to have a value then a fatal error can occur which terminates the runtime session. The developer should therefore code their scripts to avoid this from ever occurring in a deployed production system. Another way of avoiding such a fatal error is via the following two Inference Settings:

  • Raise Unassigned Errors
  • Perform inference on Unassigned objects in scripts

Numeric Decimal Accuracy in Scripting

Script assignments for numeric Objects (in both JavaScript and XpertScript) are stored with the maximum precision supported by the JavaScript engine used (e.g. by Web Browser or node.js).

For example assigning the following Numeric Object in JavaScript:

var n = 1 / 3;
#MyNumQuestion.val(n);

will result in the value of 0.33333...(recurring) regardless of the number of decimal places set for the MyNumQuestion Object.

So if the number of decimal places has been set to, a Rule condition test (such as a Decision Tree split) that compares MyNumQuestion against a fixed threshold would effectively appear as follows:

  • If MyNumQuestion < = 0.33 THEN...

But this rule would not fire because, internally, MyNumQuestion value is still greater than 0.33

Displaying the value of MyNumQuestion using Viabl.ai Dialog or Report Object will show this value to be 0.33, which can cause confusion and lead the developer to the wrong conclusion that a rule condition test has not been executed correctly!

The developer should always round the results of numeric assignments to the required number of decimal places to ensure that rules fire accurately and consistently. Alternatively if the option Round numeric Object assign to given dec places in Inference Settings is checked then script calculations are rounded automatically according to their assigned Object's number of decimal places. Beware that this option can cause loss of accuracy if intermediate calculations are also stored in Numeric Objects (in such cases the intermediate results should be assigned to local JavaScript or XpertScript numeric variables)

On This Page