Windward DocumentationWindward CoreBeginner Training CourseBeginner1: How to Populate Tables Using a ForEach Tag

1: How to Populate Tables Using a ForEach Tag

Prerequisite Tutorials

Before doing this tutorial, we recommend you have done…

  1. The Start Here Tutorial

Training Overview

This Training Guide walks you through how to populate tables with data from a ForEach tag.

Step 1- Connect to Data

ForEach tags in Windward Designer iterate over every record returned by the tags select. It is common for documents to use tables of information taken from the database, and the ForEach tag is the tool to use when you want your automated documents to display tables. ForEach tags can be leveraged to create additional rows of a table for every record, allowing your table to extend for as many rows are required to accommodate the data. Follow the steps bellow to learn how to populate a table using a ForEach tag:

1. Open Microsoft Word. Now that you’ve installed Windward Designer, you will see two new tabs in the Microsoft Office Ribbon – the “Windward” Tab and the “Windward Tools” Tab.

2. Click on the “Windward Tab” and click on the “Data Sources” button located on the left-hand side of the ribbon. This opens the Connection Editor where you will manage all of your data connections.

3. In the Connection Editor window, select the data connection labeled “SqlServer” under “Recent Inactive” and click the “Connect” button.

4. Close the Connection Editor by clicking “Close.” You have now successfully connected to the sample data!

Step 2- Design Table Template

1. Place your cursor on the first line of the template.

2. Go to the “Insert” ribbon, and click “Table

3. In the drop-down, select a 3X2 table to insert.

4. Give the columns of your table headers “Customer ID,“ “Order Date,” and “Freight.”:

5. Place your cursor in the cell under “Customer ID,” and insert a ForEach tag.

6. Place your cursor on the “[forEach:]” tag that was inserted in your template and click the “Edit Tag” button in the Windward ribbon to open the Tag Editor.

7. In the Tag Tree, expand the table : Northwind -> Tables and double-click the “Orders” table. This will automatically write a select for every column in the Orders table.

8. Go to the “Properties” and assign your tag a nickname “Orders”.

9. Click the “Save Tag” button.

10. To output data in our table, we will need to add out tags. Place your cursor after the ForEach tag in the “Customer ID” column and place an out tag. Place an out tag in the other two columns.

11. Open the Tag Editor for the Out tag in the “Customer ID” column.

12. In the Tag Tree, expand the <wr:forEach> -< varName1 and double-click the “CustomerID” node. This will automatically write a select for CustomerID currently captured by the ForEach variable.

13. Save the tag and repeat the previous two steps to select the “OrderDate” node for the “Order Date” column and the “Freight” node for the “Freight” column.

14. On the line after your table, place an EndForEach tag

Since the ForEach loop will re-produce the tag output and content captured between the ForEach and the EndForEach tags, one row of the table will be produced for every record returned by the ForEach tags select.

15. Save and output the template to DOCX output and see your results: 

We are receiving the output we expected, but it is not very useful. To reduce the number of records in our output table, we need to reduce the number of records in our select.

1. Close your output and go back to your template. Place your cursor on the ForEach tag and click the bottom of the “Wizard” button to open the drop-down. In the drop-down click “Select Wizard.” The Select Wizard will allow us to make our tag select more specific data from the Database. 

2. In the SQL Wizard, locate the “Filter” section. Adding a filter to our query will allow us to narrow down our select to fewer records of data. In this example, we will filter our select to only look at orders for the customer with CustomerID = “VICTE.”

3. Click “click here to add a group” followed by “click here to add a filter.”

4. Click on “click here to select a node” and from the “Select the desired column” dialog, select the : NorthwindTablesOrders → CustomerID node.

5. To compare the CustomerID column to the value “VICTE,” click “click here to set the value,” and in the text box that appears enter the text “VICTE”. Click enter to save the value.

6. You will notice in the preview pane of the Tag Editor only records with CustomerID = VICTE are shown. Click “OK” to save your select with the new filter.

7. Re-save your template and output to DOCX. Now your output document has much fewer rows, only displaying rows for the customer with Customer ID = VICTE.


Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.