HELP!

Dynamic Object List Values

Object Dynamic List Values (changing at runtime) should not be used if the Object's design-time List values are explicitly referenced in any Viabl.ai Knowledge or Script. For example if the list values are used in a Decision Tree split which would lead to a runtime error!

The following Object methods can be used to add or remove List values from List Objects at runtime.

  • addInstance(value name[,value properties])
  • addInstances(values array)
  • encodeInstances()
  • delInstance(value index)
  • clearInstances()

The addInstance method adds a new value to the existing list of value in a list Object. The first parameter is mandatory and represents the name of the value to be added. The second (optional) parameter is a JavaScript object which is used to set any List value properties. e.g. If the Grade object has a custom value property called displayText then:

#Grade.addInstance("CEO",
  {
    displayText: "Senior Executive"
  }
); 

You can also add multiple List Values at once (with their Value properties) by passing an array to the addInstances method. The following example assumes a custom Value property of type string called displayText.

#Grade.addInstances(
  [
    {
      _name: "Manager",
      displayText: "Senior Staff"
    }, 
    {
      _name: "Clark",
      displayText: "Junior Staff"
    }
  ]
); 

Notice that the actual list value is specified using the reserved _name system property

You can also use the encodeInstances() method to get all the object list values and their properties in a JavaScript array of objects (same format as the addInstances array)

var valuesArray = #Grade.encodeInstances();
xpertrule.message(JSON.stringify(valuesArray)); 

The delInstance(n) method deletes the nth list value from a list Object

The clearInstances() method deletes all the existing List values from a list Object

On This Page