How to Loop Through One Column of Customer Answer Table

Anne Ramey
Workflow Developers

Once you have collected answers in a table format and saved them into a JSON as specified in this solution, you will then want to use them. This How-to describes how to loop through a column of the stored data to allow for some possibilities on how to process/use these answers.

What you do with the table stored in the JSON string will entirely depend on what you want to do with it.

You may want to loop through the rows in the table and perform actions based on each a data point in a column. To do this, you will need to convert the JSON into XML with this handler. Details of constructing a loop in this data are included in the handler page. This same thing can be accomplished, with a little more precision by using the JSON Parse handler to first parse out the desired column, then loop through those results. This gives you the ability to filter out unique values if desired.

Example 1

LoopThroughOneColumn-toXML

This example uses the Utility JSON to XML handler and uses those results as the datasource of the loop. The loop path for these answer tables are

//node[@type="Array"]/node[@type="Object]/node[@name="columnName"]

This example loop just echos the column values to allow you to see the results in the Task Management Console. In practice, you could do anything with the values within the loop.

Example 2

LoopThroughOneColumn-ParseUnique

This example uses a different technique, using the Utility JSON Parse to pull the desired data out of the json, in this case unique values, and create a new XML of that column, which is used as datasource for the loop. The loop path for this is as specified for the Utility JSON Parse handler.

//items/item

Example 3

LoopThroughOneColumn-ParseAll lg To see larger image, click here and then click on the image.

This example also uses the Utility JSON Parse to pull the desired data out of the json, in this case all values, and create a new XML of that column, which is used as datasource for the loop. The loop path for this is as specified for the Utility JSON Parse handler.

//items/item

The values echoed in this case are processed in two different ways using the techniques listed here. One node finds the maximum of the column.

<%=sum=0
@results['Echo All Quantity'].collect{|key,values| sum = sum + Integer(values['output']) }.inspect
sum%>

Another node finds the sum of all the values of the column.

<%=array = []
   @results['Echo All Quantity'].collect{|key,values| array.push(values['output']) }.inspect
array.max %>