List type Objects have an extra set of system properties associated with the List values. The developer can also add their own user defined properties.
To scan list value properties often requires knowing how many values are defined in the List Object which is returned by the nValues Object property
For example:
if (#Grade.nValues == 1){
xpertrule.message("Only one list value in this question");
}
An alternative way of getting the number of list values:
if (#Grade.value().length == 1){
xpertrule.message("Only one list value in this question");
}
Each list value has a number of system properties as well as any user defined properties which can be accessed via an array as follows:
var valArr = #Grade.value();
Note that the array of JavaScript Objects returned by the above are values of the following JavaScript Object:
{
aName: string /*The internal name of the value*/
selected: boolean /*Has this value been selected*/
valid: boolean /*Is this value valid i.e.*/
visible: boolean /*Is this value visible in dialog controls*/
[User defined Value Property Name]: the type defined by the developer (Numeric or Text) /*User defined list value property*/
}
You can access the properties of the selected list value (assuming one has been selected) by specifying the value index of 0:
xpertrule.message(#Grade.value(0).aName + " : " + #Grade.value(0).displaytext);
You can access any given list value's Object by specifying the value's index:
var dirVal = #Grade.value(1); // the JavaScript Object for the first value in the list
xpertrule.message(dirVal.aName); // display the first list value
To access a user defined list value property called "displaytext":
if (#Grade.value(1).displaytext === '') {
#Grade.value(1).displaytext = "Big Boss"; // set the displaytext property of the first value in the list
}
To display the name and "displaytext" of each value in a list Object called "Grade":
var loop;
for (loop = 1; loop <= #Grade.value().length; loop = loop + 1) {
xpertrule.message(#Grade.value(loop).aName + " : " + #Grade.value(loop).displaytext);
}
Another way to access List Value properties is via the Object's inst method. This has the benefit of allowing the developer to write code that can handle different list value properties by passing the property name as a string parameter.
For example if displaytext of the first list value is empty then set it to a value:
if (#Grade.inst("displaytext", 1) === '') {
#Grade.inst("displaytext", 1, "Big Boss"); set the displaytext property of the first value in the list
}
Or, to get the list value property of the currently selected List value (assuming one has been selected):
xpertrule.message(#Grade.inst("displaytext"));
The .inst method can be called with 1, 2 or 3 parameters: