The Windward Studio

Windward Blog Home

The ForEach Tag and the Relative Select

Posted on 01/28/2015

Please Share This


“When Good Report Tables Go Bad”

AutoTag lets you create tables in your reports with ease as long as you remember one simple yet critical concept.

That concept is as follows. When you insert tags into a table, also known as a forEach loop, you need to use what’s called the relative select. This ensures your table places each piece of data, in order, in the final output.

If you don’t, well… take a look at what happens.

 A Short Example

Consider this basic template:

When you generate the report, you expect the table to look like this:


But if you don’t use the relative select, this is what you get:


How the Relative Select Works

Pieces of data are stored in nodes and placed in your report via the out tag. The out tag says “go to the node, grab a piece of data, and put it in the table.” But the out tag can’t tell the report which piece of data to grab; it simply says grab one item.

To get each piece of data from a node into the table, you use the forEach tag, which you can think of as a repeating tag.  Windward lets you repeat items based on a list of data returned. For each node or item returned, the forEach tag will repeat  everything between the beginning and ending foreach tags.

So in the above example, the forEach tag tells the report to loop through each out tag (employeeID, lastname, firstname and title) and place each data item from the out tag’s node in your table.

But here’s the kicker: You need to explicitly tell the out tags they’re being ruled by the forEach tag.

Because if you don’t, the out tags don’t know they’re supposed to call upon each item in a node, and they’ll simply grab the first data piece they see. And you’ll end up with a table that has the same line repeated over and over again.

How to “Rule” Your Table

When you select data with a forEach tag, you can create filters and select only the items you want in the forEach tag.  After this selection is done, you have a set of data with multiple items. (Think of it like a spreadsheet with many rows of data for the columns of data types you selected). This “data set” is stored in the forEach tag and referenced by the variable name assigned to that tag in the VAR section.

To relatively reference any column type of data in an out tag, you can write the select statement in the form ${VarName.ColumnName} or drag and drop from the Data Tree the item under the VARNAME node.

Therefore in the above example, to make the table loop through each employee, one after the other, you have to point the out tags at the forEach loop, not at the database table. The select will look like this (where it references the var name of the forEach tag):


Here’s how it looks in the AutoTag interface:


Do it incorrectly — that is, reference the table instead of the var name so that the select looks like this instead:

select dbo.Employees.LastName from dbo.Employees

and you’ll get a table with the same line repeated ad nauseam.

Wanna know more?

The Windward Tutor walks you through an example using the forEach tag. And you can  check out the Data Tables Video in our documentation wiki, where you’ll also find a number of tutorial videos for our wide range of reporting tools.

Please Share This

Author: Valerie Schilling

Valerie is passionate about people. Her strengths, with many years in the tech industry, are deeply rooted in relating and communicating. Valerie has an unparalleled tenacity to ensure the people she works with get what they need. Even if your problem is not solved immediately, your day will be brightened by her intelligent and cheerful demeanor.

Other posts by