3: If Tag Tutorial

Prerequisite Tutorials

Before doing this tutorial, we recommend you have done…

1. The Start Here Tutorial

Training Overview

This Training Guide walks you through the fundamentals to understand and use the If, Else and EndIf tags.

1. What do If, Else and EndIf Tags do?

2. Connect to Data

3. Design and fill a table template using ForEach

4. Analyzing the Output

Step 1- What do If, Else and EndIf Tags do?

If Tag are used to conditionally display content in your Report Template, such as Tags, text, images, etc., in your output. An If Tag is basically a Boolean expression, or condition, such as "${varName} <= 10" (${varName} is less than or equal to 10), whose value determines whether the contents of the If Tag are processed. If the condition evaluates to 'true,' then the content between the If Tag and the EndIf Tag are processed. If the condition evaluates to 'false,' then the content between the If Tag and the EndIf Tag are ignored.

For example, if you only want to see prices for items that show a cost that is less than or equal to 10, you could display only those prices using a condition such as "${CostOfItems} <= 10” and ignore the cost of other items in the list.

Since the If tag is only processed when the condition evaluates to 'true,' users can use an Else tag to display content in the case that the If tag evaluates to 'false.' For example, you may wish to print "the cost of this item is less than or equal to 10" if "${CostOfItems} <= 10" evaluates to 'true;' otherwise print "the cost of this item is greater than 10."

Step 2 - Connect to Data

1. Open Microsoft Word. You will see two 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 to open the connection editor.

3. In the Connection Editor window, select the data connection labeled “SQLServer” and click the “Connect” button.

4. Close the Connection Editor. You have now successfully connected to the sample data!

Step 3 - Design and fill a table template using ForEach

Using the ForEach tag, you will first make a basic table that displays a variety of product information.

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 “Category Name,” “Product Name,” and “Units In Stock.”

5. Place your cursor in the cell under “Category Name,” 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 mssql.windward.net : Northwind -> Views and double-click the “Products by Category” view. This will automatically write a select for every column in the Products by Category view.

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

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 “Category Name” 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 “Category Name” column.

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

13. Save the tag and repeat the previous two steps to select the “ProductName” node for the “Product Name” column and the “UnitsInStock” node for the “Units In Stock” 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 as is. To further analyze the output and determine if certain standards are met, we can use the If, Else, and EndIf tags.

Our goal is to determine which products are beverages and which products are food. Then after we separate our products into the two categories, we want to look at the Units In Stock values to see which products will need to be ordered.

Step 4 – Analyzing the Output

To denote which products are beverages and which products are food, we need to add two columns to the table between “Category Name” and “Product Name.”

1. Add two columns to the right of the “Category Name” column. Give the new columns of your table headers “Beverages” and “Food.”

2. Place your cursor in cell below “Beverages” and insert an If tag.

3. Place your cursor on the If tag that was inserted in your template and click the dropdown under the “Wizard” button in the Windward Ribbon, then select “Condition Wizard” from the dropdown options to open the Condition Wizard.

4. Select the line labeled “click here to enter a condition” and another line will appear in its place after your selection.

5. Now select the line labeled “click here to select a node” that appeared.

6. Using the dropdown available expand the Tag Tree, then expand varName1 and double-click the “CategoryName” node.

We don’t need to change the line labeled “equal to” as that is the value we will be using for this condition.

7. Select the line labeled “click here to set the value” and enter the value “Beverages” then press enter. Now select “OK” in the corner to exit the selection wizard.

If the CategoryName is equal to “Beverages,” then we want to denote that in the “Beverages” column.

8. Place your cursor after the If tag, then type the letter “x.”

9. Place your cursor directly after the letter “x” and insert an EndIf tag.

We now need to follow similar steps for the “Food” column in order to denote when a product has a Category Name that isn’t equal to “Beverages.”

10. Place your cursor in cell below “Food” and insert an If tag.

11. Place your cursor on the If tag that was inserted in your template and click the dropdown under the “Wizard” button in the Windward Ribbon, then select “Condition Wizard” from the dropdown options to open the Condition Wizard.

12. Select the line labeled “click here to enter a condition” and another line will appear in its place after your selection.

13. Now select the line labeled “click here to select a node” that appeared.

14. Using the dropdown available expand the Tag Tree, then expand varName1 and double-click the “CategoryName” node.

15. Select the line labeled “equal to” then select “not equal“ from the dropdown.

16. Select the line labeled “click here to set the value” and enter the value “Beverages” then press enter. Now select “OK” in the corner to exit the selection wizard.

If the CategoryName is not equal to “Beverages,” then we want to denote that in the “Food” column.

17. Place your cursor after the If tag, then type the letter “x.”

18. Place your cursor directly after the letter “x” and insert an EndIf tag.

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

The resulting output shows an “x” in the column of “Beverages” for products that are beverages or an “x” in the column of “Food” if the products are food. Now we want to look at the “Units In Stock” column to determine which products need to be ordered.

20. Place your cursor directly before the tag labeled UnitsInStock and insert an If tag.

21. Place your cursor directly after the tag labeled UnitsInStock and insert an EndIf tag.

22. Place your cursor on the If tag that was inserted in your template and click the dropdown under the “Wizard” button in the Windward Ribbon, then select “Condition Wizard” from the dropdown options to open the Condition Wizard.

For UnitsInStock values that are greater than 15 we want to just output the UnitsInStock value, but for any UnitsInStock values less than or equal to 15 we want to show a value of “Need to Order” instead.

23. Select the line labeled “click here to enter a condition”, another line will appear in its place after selecting, now select the line labeled “click here to select a node” that appeared.

24. Using the dropdown available expand the Tag Tree, then expand varName1 and double-click the “UnitsInStock” node.

25. Select the line labeled “equal to” then select “greater than” from the dropdown.

26. Select the line labeled “click here to set the value” and enter the value “15,” then press enter.

27. Select “OK” in the corner to exit the selection wizard.

In order to change the values less than or equal to 15 to display “Need to Order,” we will use an Else tag.

28. Place your cursor directly after the tag labeled UnitsInStock and insert an Else tag.

We use the Else tag to specify what to do if an If tag’s condition evaluates to ‘false.’ If an If tag's condition evaluates to 'false,' then the tags and/or text between the Else tag and EndIf tag are processed. This means we need to place the text we want to output between the Else tag and EndIf tag.

29. Place your cursor directly after the Else tag and type the phrase “Need to Order.”

30. Now you can output your finished template! Re-save your template and output to DOCX.

Next Steps

Now that you have finished this introduction tutorial, here are some resources we recommend you visit next:

  1. How to connect to SQL datasources
  2. How to use the XPath Wizard
  3. The Windward Tutor: A collection of short video tutorials

0 Comments

Add your comment

E-Mail me when someone replies to this comment