How Do I Use the Switch, Case and EndSwitch Tags?

Switch, Case and EndSwitch Tags are used when you wish to test for multiple different conditions, and manipulate your output depending on which condition is met.  

Switch Tags are used to begin a list of Case Tags, and EndSwitch Tags are used to end that list. Each Switch Tag must have a corresponding EndSwitch Tag.

Each Case Tag evaluates a different condition. Then the Tags, text, etc., after the first condition that is met, and before the next Case Tag, are executed or displayed. If the last Case Tag's condition is met, then the Tags, text, etc., before the EndSwitch Tag are executed or displayed.

We'll work through an example of using Switch, Case and EndSwitch Tags using the attached report template and images. The template connects to our public SQL Server; if you aren't familiar with connecting to a SQL Server, see How to Connect to an MS SQL Server.

As you can see, our example template is a Word table of customer information. The table was built with a ForEach Tag, and has an Out Tag in each column except the last. In the last column, we'll insert Switch, Case and EndSwitch Tags to control the display of country flags for each customer.

The output now looks like:

Place your cursor in the empty cell beneath the "Country" header, and use the Tags button on the AutoTag ribbon to select a Switch Tag:

Double-click on the Switch Tag to bring up the Tag Editor, and give it the nickname "Country". Save the Tag:

Place your cursor after the Switch Tag, and insert a Case Tag the same as you inserted the Switch Tag. Double-click on the Case Tag to bring up the Tag Editor.

In the Tag Editor, create the select statement in the Query Pane:

  1. Expand the ForEach Tag's ${var1} variable in the Data Pane
  2. Drag and drop "CountryRegionName" from the Data Pane to the Query Pane
  3. Complete the select statement by adding " == 'Australia'"
  4. Click on the Evaluate button

The completed select statement should be "=${var1.CountryRegionName} == 'Australia'" (without the quotes).

Give the Tag the nickname "Australia?" as you did for the Switch Tag above, and save the Tag.

Place your cursor after the [Australia?] Case Tag, and use the Word Insert Pictures button to insert the australia_flag.png image:

Your template should look like this:

Repeat this procedure to add Case Tags and images for Canada, Mexico and the United States. The queries for the Case Tags should look like:

  • =${var1.CountryRegionName} == 'Canada'
  • =${var1.CountryRegionName} == 'Mexico'
  • =${var1.CountryRegionName} == 'United States'

And the template should look like:

Now that we have created all of the Case Tags, and inserted the images that will be displayed when the Case Tags' conditions are met, we must remember to insert the EndSwitch Tag. Place your cursor after the image of the United States flag, and use the Tags button to insert an EndSwitch Tag:

Finally, here is the completed template:

And here is our output: