A long-awaited feature made it earlier in Oracle Digital Assistant 21.10. Starting with Oracle Digital Assistant 21.10, the System.CommonResponse component has a new iteratorExpression property that enables the component to display values from arrays stored in a nested object as would be returned from a REST service call. This article explains how to work with this new feature.

The problem solved by the new iteratorExpression

The System.CommonResponse component in Oracle Digital Assistant can loop through arrays to print multiple message responses or dynamically generate action items based on the content in that array. 

A limitation of this functionality in versions prior to Oracle Digital Assistant 21.10 was that the array had to be a top-level element of a variable. In other words, the iterator required a variable reference added to its iteratorVariable property, which often required developers to copy the content of a REST service result set into a variable before the contents could be displayed in a list. With the iteratorExpression property, this intermediate step is no longer required.

How to use the iteratorExpression

The sample code below creates an object with a property items holding an aarray for employee names and employee Id. The variable mocksup a result set returned from a REST call. 

At runtime in the conversation tester, the names of the employees should be displayed in a list of values, whereas the other content of the object saved in the variable should be used to display the prompt

The BotML (YAML) code below shows how the iteratorExpression is used to display the information shown in the screen shot above. The expression is an Apache FreeMarker expression and references the items property in the variable. The iteratorVariable property is used to define a name to the array handle. In teh example below, the iteratorVariable property is set to data, which means that the employee name and employee Id of eah employee is referencable through ${data.employeeName} and ${data.employeeId}.  

The text response item of the System.CommonResponse component references the variable directly to read the department Id and department name from it. 

 

 

Author