---
title: "Exercise 4 - Populating a Word Template"
canonical: "https://docs.getxporter.app/space/XPORTERCLOUD/429879/Exercise%204%20-%20Populating%20a%20Word%20Template"
format: markdown
---
> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> > Macro (toc)

# Introduction

In this exercise, you'll learn how to populate a Word [template](https://docs.getxporter.app/space/XPORTERCLOUD/427622) with a table of contents (TOC).

> Macro (rw-ui-steps-macro)
> 
> > Macro (rw-step)
> 
> Open an empty Word document.
> 
> > Macro (rw-step)
> 
> Create a cover page. Go to *Insert *-> *Cover Page* and select one of your choice.
> 
> > ℹ️ The cover page is populated from the document properties. You can:
> > ℹ️ 
> > ℹ️ 1. <span style="color: #0d0d0d">Place your desired text in the designated areas on the cover page.</span>
> > ℹ️ 2. Insert it into the correct document property.
> > ℹ️ 3. Apply a mapping to the document property.
> > ℹ️ 
> > ℹ️ You'll see [examples](https://docs.getxporter.app/space/XPORTERCLOUD/429879/Exercise+4+-+Populating+a+Word+Template#Examples) of this in this exercise.
> 
> > Macro (rw-step)
> 
> After creating the cover page, the second page is blank. Insert a table of contents. Go to *References* -> *Table of Contents* select the *Automatic Table 1*.
> 
> > ℹ️ The table of contents is going to have three levels:
> > ℹ️ 
> > ℹ️ 1. <span style="color: #0d0d0d">Heading 1 represents the first level.</span>
> > ℹ️ 2. <span style="color: #0d0d0d">Heading 2 represents the second level.</span>
> > ℹ️ 3. <span style="color: #0d0d0d">Heading 3 represents the third level.</span>

# Populating a Word Template with a Table of Contents

The Template in this scenario will export a list of [Bugs](https://docs.getxporter.app/space/XPORTERCLOUD/429879/Exercise+4+-+Populating+a+Word+Template#Bugs), and then a list of [Stories](https://docs.getxporter.app/space/XPORTERCLOUD/429879/Exercise+4+-+Populating+a+Word+Template#Stories) (Issue types). These will be the **first level** of the TOC. For each Issue exported, in both Issue types there will be:

- The Key, which will be the TOC's **second level.**
- The Comments and Linked Issues, which will be the TOCs **third level**.

## Bugs

> Macro (rw-ui-steps-macro)
> 
> ### Bugs
> 
> > Macro (rw-step)
> 
> Below the TOC, insert a page break.
> 
> > Macro (rw-step)
> 
> Insert the title "Bugs" and set up the style to *Heading 1*.
> 
> > Macro (rw-step)
> 
> Below the title, create the following section that will list all the issues being exported of the type *Bug*.
> 
> | **&{for issues|filter=%{'${IssueTypeName}'.equals('Bug')}}** |
> | --- |
> 
> ### Key
> 
> > Macro (rw-step)
> 
> Insert a new title, "${Key}", to identify each issue in the TOC and set the style to *Heading 2.*
> 
> > Macro (rw-step)
> 
> Extract the issue summary. For this, include the corresponding [mapping](https://docs.getxporter.app/space/XPORTERCLOUD/558575) on the template.
> 
> ### Links
> 
> > Macro (rw-step)
> 
> For each issue, you'll want to export its linked issues. However, you'll only want to print this information in the final document if there are issue links. Insert this [Conditional Block](https://docs.getxporter.app/space/XPORTERCLOUD/527146):
> 
> | **#{if (%{${LinksCount} > 0})}** |
> | --- |
> 
> > Macro (rw-step)
> 
> Name this iteration "Links" and set the style to *Heading 3*.
> 
> > Macro (rw-step)
> 
> Insert the *Links* table header:
> 
> | **Key** | **Summary** | **Link Type** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Below the header, include the `#{for links}` or `#{for <VariableName>=LinksCount}` statement, so the header is printed only once.
> 
> > Macro (rw-step)
> 
> Create another table where the *Issue Links* will be populated:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Links[n].Key} | ${Links[n].Summary} | ${Links[n].LinkType} |
> 
> > Macro (rw-step)
> 
> Close the *Links* statement using the mapping `#{end}` and the Conditional Block statement with another `#{end}`
> 
> ### Issue Comments
> 
> > Macro (rw-step)
> 
> Repeat the same process to iterate the Issue Comments.
> 
> > Macro (rw-step)
> 
> Insert the Conditional Block to know if there are comments on the Issue:
> 
> | **#{if (%{${CommentsCount} > 0})}** |
> | --- |
> 
> > Macro (rw-step)
> 
> The title for the second Iteration can be "Comments". Set the style to *Heading 3*.
> 
> > Macro (rw-step)
> 
> Insert the Links table header:
> 
> | **Author** | **Body** | **Date** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Below the header, add the `#{for comments}` or `#{for <VariableName>=CommentsCount}` statement, so the header is printed only once.
> 
> > Macro (rw-step)
> 
> Create another table where the Issue Comments will be populated:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Comments[n].Author} | ${Comments[n].Body} | ${dateformat("yyyy-MM-dd hh:mm"):Comments[n].Created} |
> 
> > Macro (rw-step)
> 
> Close the *Links *and *Conditional Block* statements and the *Bugs* section using the mapping `#{end}`

## Stories

> Macro (rw-ui-steps-macro)
> 
> > Macro (rw-step)
> 
> Repeat the process above, but now for the Stories. Start by inserting a page break.
> 
> > Macro (rw-step)
> 
> Insert a title named "Stories" and set the style to* Heading 1*.
> 
> > Macro (rw-step)
> 
>  Below the title, create the following section that will list the issues of the type *Story*.
> 
> | **&{for issues|filter=%{'${IssueTypeName}'.equals('Story')}}** |
> | --- |
> 
> > Macro (rw-step)
> 
> Insert the second level of the TOC with the issue "${Key}" and extract the issue *Summary* on the next line of the document.
> 
> ### Issue Links and Comments
> 
> #### Links
> 
> > Macro (rw-step)
> 
> Repeat the previous steps to iterate the Issue Links and Comments. Include:
> 
> | **#{if (%{${LinksCount} > 0})}** |
> | --- |
> 
> > Macro (rw-step)
> 
> Insert "Links" as a title for this Iteration and set up the style to *Heading 3*.
> 
> > Macro (rw-step)
> 
> Add the *Links* table header:
> 
> | **Key** | **Summary** | **Link Type** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Include the `#{for links}` or `#{for <VariableName>=LinksCount}` statement. 
> 
> > Macro (rw-step)
> 
> Insert this table to export the links:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Links[n].Key} | ${Links[n].Summary} | ${Links[n].LinkType} |
> 
> > Macro (rw-step)
> 
> Close the Iteration with `#{end}` and the Conditional Block with another `#{end}`
> 
> #### Comments
> 
> > Macro (rw-step)
> 
> Insert the Comments sections:
> 
> | **#{if (%{${CommentsCount} > 0})}** |
> | --- |
> 
> > Macro (rw-step)
> 
> Name this Iteration "Comments" and set the style to *Heading 3*.
> 
> > Macro (rw-step)
> 
> Insert the Comments table header:
> 
> | **Author** | **Body** | **Date** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Include the `#{for comments}`or `#{for <VariableName>=CommentsCount}` statement.
> 
> > Macro (rw-step)
> 
> Insert the table to export the Comments:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Comments[n].Author} | ${Comments[n].Body} | ${dateformat("yyyy-MM-dd hh:mm"):Comments[n].Created} |
> 
> > Macro (rw-step)
> 
> Close the Iteration with `#{end}` and the Conditional Block with another `#{end}`
> 
> > Macro (rw-step)
> 
> Finish the section of Stories with `&{end}`

> ℹ️ The template is now complete.

## Populating the TOC

> Macro (rw-ui-steps-macro)
> 
> > Macro (rw-step)
> 
> Go to the TOC, which is empty, and select it.
> 
> > Macro (rw-step)
> 
> Right-click and click *Update Field*.
> 
> > Macro (rw-step)
> 
> Update the entire table <span style="color: #0d0d0d">to ensure it reflects the document's current structure</span>.
> 
> > Macro (rw-step)
> 
> Click *OK*. The TOC will now display the three levels that you have created along the template.

> ℹ️ - <span style="color: #0d0d0d">Your template is now ready for use.</span>
> ℹ️ - You can create more levels using different styles.
> ℹ️ - <span style="color: #0d0d0d">Experiment with additional styling options and iterations to further customize your output (for example attachments, worklogs, etc.).</span>

## Examples

Below (Figure 1 and 2) there are samples of how the mappings will be displayed in a Word template.

![Figure 1 - Word template](media://dd277180-9301-4394-99ad-6d6dbd07a602)

![Figure 2 - Word template](media://0dd300ab-6adf-4f71-a4d8-d89f96c71cb4)

This Template (Figure 1 and 2) includes:

- A header with an image (Figure 1 - 1)
- Headings (Figure 2 - 1)
- Text styling (Figure 1 - 2).
- A table (Figure 2 - 2).
- A TOC (Figure 1 - 3).
- A cover page (Figure 1 - 1).

Below (Figure 3 and 4) there are samples of how the generated template will be populated.

![Figure 3 - Populated template](media://69ed6183-a191-491c-9fed-e314aec230f8)


![Figure 4 - Populated template](media://b4814908-1706-48fb-bb90-76f350f54840)


> ℹ️ **This exercise is now complete. Proceed to **[**Exercise 5**](https://docs.getxporter.app/space/XPORTERCLOUD/429753)** to learn **<span style="color: #000000">**how to populate a template representing a project overview.**</span>
> ℹ️ 
> ℹ️ If you like this exercise, please share your opinion on the page by just leaving a comment or a 👍. Your opinion is very important to us.
> ℹ️ 
> ℹ️ Thank you in advance. Enjoy our product!

<details>
<summary>Exercise 4 Resources</summary>

| **File** | **Description** |
| --- | --- |
|  | Exercise 4 - Sample template file |
|  | Exercise 4 - Sample generated file |
</details>


<details>
<summary>Support/Troubleshooting</summary>

If you have questions or technical issues, please [contact the Support team via the Customer Portal (Jira service management)](https://jira.getxray.app/servicedesk/customer/portal/2/user/login?destination=portal%2F2%2Fcreate%2F28) or [send us a message using the in-app chat](https://docs.getxporter.app/space/XPORTERCLOUD/18251779/In-App+Chat+Support).
</details>