---
title: "Exercise 2 - Populating the Links of Your Issue"
canonical: "https://docs.getxporter.app/space/XPORTERCLOUD/528259/Exercise%202%20-%20Populating%20the%20Links%20of%20Your%20Issue"
format: markdown
---
> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> > Macro (toc)

# Introduction

In this exercise, you'll learn how to populate the Issue links of an issue and print a message when there are none, using an [Xporter Template](https://docs.getxporter.app/space/XPORTERCLOUD/427622). 

The mappings in use are documented [here](http://confluence.xpand-addons.com/display/public/XPORTERCLOUD/Iterations#Iterations-IteratingIssueLinks).

# Populating the Links of Your Issue

> Macro (rw-ui-steps-macro)
> 
> > Macro (rw-step)
> 
> The section between `#{for links}` and `#{end}` will grow dynamically according to the number of existing links on the Issue.
> 
> > Macro (rw-step)
> 
> To begin iterating the Issue links, at the beginning of the iteration section of your template, put the mapping `#{for links}`.
> 
> > Macro (rw-step)
> 
>  At the end of that section on your document, put the mapping `#{end}` to close it.
> 
> > Macro (rw-step)
> 
> Put `Links[n].` at the beginning of the mapping of the Link field you're trying to populate.
> 
> > Macro (rw-step)
> 
> When using the `#{for links}` statement, the variable name will always be `n`. If you want to use a different variable name, like `b`, start your iteration with the statement `#{for b=LinksCount} (`make sure to change it properly on the `Links[b].` at the beginning of the mapping of the Link Field you're trying to populate):
> 
> ```
> #{for links}
>    ${Links[n].AppType}
>    ${Links[n].LinkType}
>    ${Links[n].Key}
>    ${Links[n].Summary}
>    ${Links[n].URL}
> #{end}
>  
> or
>  
> #{for <VariableName>=LinksCount}
>    ${Links[VariableName].AppType}
>    ${Links[VariableName].LinkType}
>    ${Links[VariableName].Key}
>    ${Links[VariableName].Summary}
>    ${Links[VariableName].URL}
> #{end}
> ```
> 
> > Macro (rw-step)
> 
> You can use a Conditional Block `#{if...}` to decide whether to iterate or not.
> 
> > ℹ️ To use [conditional blocks](https://docs.getxporter.app/space/XPORTERCLOUD/527146), [iterations](https://docs.getxporter.app/space/XPORTERCLOUD/428318) or mappings, you can use the JavaScript language inside them. The notation to use the JavaScript on your mappings is: `%{<Javascript>}`
> > ℹ️ 
> > ℹ️ You can check examples [here](https://docs.getxporter.app/space/XPORTERCLOUD/460547/JavaScript).
> 
> > Macro (rw-step)
> 
> If the Issue **doesn't have links**, you can set a message to be displayed instead.
> 
> ```
> #{if (%{'${LinksCount}' == 0})}
> Doesn't have links.
> #{end}
> ```
> 
> If the Issue **has links**, you can set the message to display the number of links, along with the links Iteration.
> 
> ```
> #{if (%{'${LinksCount}' > 0})}
> There are ${LinksCount} links.
> #{for links}
> AppType: ${Links[n].AppType}
> LinkType: ${Links[n].LinkType}
> Key: ${Links[n].Key}
> Summary: ${Links[n].Summary}
> URL: @{title=${Links[n].URL}|href=${Links[n].URL}}
> #{end}
> #{end}
> ```
> 
> > ℹ️ Xporter for Jira Cloud also allows generating [hyperlinks](https://docs.getxporter.app/space/XPORTERCLOUD/527053/Wiki+Markup%2C+HTML+and+Links) on the fly. We have created a hyperlink on the mapping URL on the code above.
> 
> > ⚠️ When creating an [Excel template](https://docs.getxporter.app/space/XPORTERCLOUD/558471), use: `${link:title=${Key},href=${BaseURL}/browse/${Key}`
> 
> > Macro (rw-step)
> 
> If you want to display your links iteration as a table, put the conditional block above the header:
> 
> ```
> #{if (%{'${LinksCount}' == 0})}
> No have links.
> #{end}
> #{if (%{'${LinksCount}' > 0})}
> There are ${LinksCount} links.
> ```
> 
> > Macro (rw-step)
> 
> Then, the links table header:
> 
> | **Key** | **Summary** | **URL** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Below the table header, put 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} | @{title=${Links[n].URL}|href=${Links[n].URL}} |
> 
> > Macro (rw-step)
> 
> Close the Links statement using the mapping `#{end}` and the Conditional Block statement with another `#{end}`
> 
> ```
> #{end}
> #{end}
> ```
> 
> > ℹ️ There are [more fields inside the iteration links that you can populate](https://docs.getxporter.app/space/XPORTERCLOUD/428318/Iterations).
> > ℹ️ 
> > ℹ️ You can [apply this to other types of Iterations](https://docs.getxporter.app/space/XPORTERCLOUD/428318/Iterations).
> 
> ## Examples
> 
> Below (Figure 1) is a sample of how the mappings will be displayed in a Word template.
> 
> ![Figure 1 - Word template](media://c4983b5b-9213-4398-b3b2-80c60c0668f2)
> 
> This Template (Figure 1) includes:
> 
> - A header with a logo (Figure 1 - 1).
> - Headings (Figure 1 - 2).
> - Text styling (Figure 1 - 3).
> - A table (Figure 1 - 4).
> 
> Below (Figure 2) is a sample of how the generated file will be populated.
> 
> ![Figure 2 - Populated file](media://4d986c71-c288-4f51-99c2-40630c18b101)
> 
> or
> 
> ![Figure 3 - Populated file](media://5306550f-915e-4a86-9494-fe20c4076368)


> ℹ️ **This exercise is now complete. Proceed to **[**Exercise **](https://docs.getxporter.app/space/XPORTERCLOUD/461583/Exercise+3+-+How+to+Populate+the+JQL+Queries)<span style="color: #0055cc">[**3**](https://docs.getxporter.app/space/XPORTERCLOUD/461583/Exercise+3+-+How+to+Populate+the+JQL+Queries)</span>** to learn h****ow to populate the JQL queries.**
> ℹ️ 
> ℹ️ If you like this exercise, please leave a comment or a 👍. Your feedback is very important to us.
> ℹ️ 
> ℹ️ Thank you in advance. Enjoy our product!

<details>
<summary>Exercise 2 Resources</summary>

| **File** | **Description** |
| --- | --- |
|  | Exercise 2 - Sample Template file |
|  | Exercise 2 - Sample generated file |
|  | Exercise 2 - Sample generated file without links |
</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>