HELP!

How to implement Looping around Knowledge Objects?

Looping is where something is executed repeatedly until an exit criteria is met. There are 2 ways to implement Looping in the Viabl.ai Platform

  • Using Jumps in Decision Flow Trees and Decision Trees to Loop back to a previous node.
  • Using Looping commands inside a Script (XpertScript or JavaScript)

Either way, there are 2 main considerations when implementing looping in the Viabl.ai Platform:

  • Ensure that your looping exit criteria is correct and achievable (to prevent infinite loops which cause the runtime engine to crash)
  • Less obvious is the need to ensure that any variable Viabl.ai Platform Object inside the loop that represents multiple data instances (or effecting the exit criteria) is "re-prompted for" (for Questions) or "re-evaluated" (for Decision Trees, Decision Tables, Calculated Attributes, etc). By default (expect for Decision Flow Trees) the first time a variable Viabl.ai Platform Object is executed (to obtain it's value), this value is used during all subsequent Knowledge checks (for example if the same Question is split upon in Decision Trees multiple times). Therefore if a question has multiple instances then it must be prompted for each time it is encountered inside the loop. If the question impacts the Looping exit criteria then you must consider if there is a need to "prompt for" a new value when it is encountered again inside this loop. The same applies to Knowledge Objects (such as a Decision Trees and Calculated Attributes) once they are executed once, the outcome/calculation reached the first time is used if they are encountered again. There are two methods to achieve this (forcing of the "re-prompt for" or "re-evaluate):
    • Switching the Object's Dynamic Inference (isDynamic) setting to True will ensure that the Object is "prompted for" /"evaluated" every time it is encountered by Knowledge inference.
    • Clearing any exiting value using the Object's clear method via a (JavaScript) Script before it is encountered again during knowledge inference
#ObjectName.clear();

Note that if a Knowledge Object such as Decision Tree or a Calculated Attribute is included inside a loop, then it's Dynamic Inference setting must be set to True (as well as the Questions used inside these Knowledge Objects)

In the following example, the Decision Flow Tree captures the Name and Age of up to 10 members in a group. If one or more of the members is over the age of 18 then the group is accepted, otherwise an "Adult Supervisor" must accompany the group:

image descr

In the above example the Dynamic Inference should be set as follows:

  • For "Name" and "Age" set to True as these must be prompted for in every iteration to capture/process multiple sets of the data
  • For "Finished_Members" set to True so it is prompted for in every iteration to determine when to exit the loop
  • For "Counter" set to False so it is never prompted for as it is being incremented via a script outside the Object in the above example. However if the incrementing of "Counter" was to be made inside the OnCatputre Event of "Counter" then it's "Dynamic Inference" would have to be set to True to ensure that the Event's script is executed in every iteration.
  • For "Adult_Supervisor" set to False to ensure that it is only prompted for if all members are under the age of 18.

To change the Dynamic Inference setting for an Object, select this Object in the Object Catalog then select the menu option Knowledge Maintenance -> Dynamic Inference

image descr

Note that the Dynamic Inference for an Object can also be set by changing its isdynamic property via the Edit Advanced Settings menu or during runtime via a (JavaScript) Script:

#Age.prop("isdynamic", true);

Also note that an Array (Viabl.ai Platform Object or JavaScript) could be used (via a Script) to hold the multiple values captured.

On This Page