article by Frank Nimphius, August 2019
Value lists can be displayed using the System.List, System.CommonResponse and SystemResolveEntities component in Oracle Digital Assistant. A challenge for developers that is addressed in this article is how to sort entity derived lists.
Lets use a simple example in which an entity is defined that contains "Yes" and "No" as a value.
By default, the sorting of the list values is ascending, which means that the list of "Yes" and "No" values will be displayed with the "No" option first. This order doesn't change if you provide the "Yes" value option first when defining the entity.
To sort the displayed list, you use the System.List component along with Apache FreeMarker expressions.
This then returns the reverse order of the list options as shown in the image below. The type.enumValues reference works for value list entities and returns a comma separated string for the list values. Using the Apache FreeMarker split(',') built-in expression, the string is turned into an array. The Apache FreeMarker reverse expression then sorts the array in reverse order. The join(',') built-in expression is then used to create a comma separated string from the array, for use in the System.List component.
Doing the same with the System.CommonResponse component
To use the System.CommonResponse component to display a sorted list of entity values, Apache FreeMarker expressions wont work. Here you need to create a custom component that you pass the comma delimited values (<variableName>.type.enumValues) to and that then writes the values as an array to a context variable in the dialog flow.
The context variable is then referenced from the "System.CommonResponse" component iteratorVariable property. A reason for why the System.CommonResponse component requires a custom component is that it is set-up to deal with more complex objects than an array of strings. The System.CommonResponse component can display an array of objects (as it would be needed e.g. with cards).
The System.List component only displays comma delimited string values and therefore could use the Apache FreeMarker text used in the sample
Related Content
TechExchange Quick-Tip: Accessing Attribute Names and Values of a Data Object
TechExchange – Using Apache Freemarker Expression in Oracle Intelligent Bots
TechExchange Quick-Tip: Customizing the Oracle Bots Node.js SDK Component Template