An If Tag allows you to display conditional information in your report. When you create an If Tag, you are setting the criteria for the condition and creating the information to be displayed if the data meets that criteria. This information can consist of additional Windward Tags, text, images, tables and about anything you can create in Microsoft Office.
- If the result of the If Tag (and all the content between the initial If Tag and End If Tag) is true, that all content will be printed normally in the final report.
- If the result of the If Tag (and all the content such as tags, text, images, etc., between the initial If Tag and EndIf Tag) is false, all of that content will not be printed in the final report.
Create a table in which you will place an If Tag.
Below is a table from the Northwind XML data explained in Data Sourcing.
NOTE: If you're working with an SQL database, you'll have slightly different language in the table. Also make sure to note the notEmpty Property for SQL (explained in Step 1).
The table above starts with a ForEach Tag which has been re-named with the nickname “EmployeeList”. Remember, it is important to know the name (also referred to as the "var") of the ForEach Tag, because you'll need this information to create your If Tag. This tag is followed by four Out Tags: [EmployeeID], [LastName], [FirstName], and [Title]. Finally, the EndForEach Tag is placed outside the table.
Step 1: Determine the Condition for the "If"
Suppose in the above example that we don't want to see the exact job title of each employee. Instead, all of the sales representatives are being promoted, and we want a table that will tell us at a glance who is due for a promotion. We want the output under Title to display the word "Promotion" if an employee is a sales representative.
Delete the Out Tag under "Title" (as shown above). Now we're ready to create our If Tag.
This property is used when a query to your data source returns nothing; Windward needs to know how to handle such a case. For example, if you asked your data source how many employees are eligible for promotion but none are, then that information can be confusing to a Windward Tag. The tag (or the code behind the scenes) is not able to do additional work on a value that does not exist.
In the If Tag you can set the notEmpty property to true or false. This property is only used for a SQL select that returns zero rows off information, or an XPath select that returns a text that has a length of zero.
For the case of returning a node that exists but is empty:
notEmpty = true (meaning the node does contain data)
notEmpty=false (meaning the node does not contain data)
The bottom line is that you should generally set the notEmpty property to true, and know that if a section doesn't print, the dataset may have nothing in it. You can troubleshoot from there.
Step 2: Insert an If Tag
Click in the cell where you want the tag to appear (in this case, the cell under "Title") and click the Tags button on the AutoTag ribbon. Click the If Tag icon to insert the If Tag in the current location.
Step 3: Open the Tag Editor
Double-Click the If Tag you’ve just inserted under "Title." The Tag Editor will pop-open. Then, click the Select tab.
Step 4: Build condition in the Wizard or Select Bar
What you do next will depend upon your data source. If you're using an XML file, you will use the XPath Wizard. If you're using an SQL data source, you will be working directly with the Select Bar or with the SQL Wizard.
We'll walk through the XPath Wizard for this example, however, the same applies to the SQL Wizard.
The XPath Wizard
Click the Wizard:
This opens the Wizard dialog box.
- In the left pane, click the statement: [click here to add a node]
A. Now you must tell AutoTag where to look for the data. Because you're inside a ForEach loop, here you will choose the name of the ForEach variable. In this case, our var is named EmployeeList. In the dialog box that appears, click the node EmployeeList, and click OK.
B. The data returned from the first entry of the var EmployeeList loop appears in the right pane of the wizard, helping you confirm that you've chosen the correct node. Your next step is to set up the basis of the condition. In the left pane, click the statement [click here to add a group]:
And then, in the left pane, click the statement [click here to add a condition]:
C. Now you're ready to start adding information to the condition. The condition is made up of three parts:
- Node - the data value to compare
- Comparison - the inequality conditions used to compare the two values
- Value - the filter value you want to compare the loop changing 'node value' against
D. Click the first part, the statement [click here to select a node]. In the right pane of the dialog box, click the node upon which you want to place the condition – in this case, the Title node.
E. Click the second part, the comparison. By default, the comparison is set to equal to. From the context menu, select the appropriate comparison – in this case, equal to is the correct comparison.
F. Click the third part, the value. In the drop-down menu, type the appropriate value for the Wizard to look for in your data – in this case, "Sales Representative."
You can see the entire select statement (the query that will be sent to the data source when you run the report) in the lower pane of the wizard written in full XPath language (which you did not even have to write or understand!) Click OK. This closes the XPath Wizard.
Click Save Tag.
Step 5: Enter the conditional text to be displayed
Now that the formatting of the If Tag has been taken care of, you can enter the text you want displayed. Your table looks like this:
Click the last cell immediately after the closing angle bracket for the If Tag and type the word "Promotion":
Step 6: Close the If Tag with EndIf Tag
Click the last cell immediately after the word "PROMOTION." Open the Tag Builder, click the EndIf Tag icon, and click OK.
The table now looks like this:
Step 7: Preview the report by clicking the "Output" button
Save your report template as a document. Then, from the Output Options, click the desired report format icon. In this example, we chose to view the report as a PDF file, and this is the result:
Great; you've successfully created an If Tag. Now that you've mastered that, we'll introduce you the If Tag's cousin, the Else Tag.