---
title: "Exercise 5 - Populating Set Functions"
canonical: "https://docs.getxporter.app/space/XPORTERCLOUD/559654/Exercise%205%20-%20Populating%20Set%20Functions"
format: markdown
---
> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> > Macro (toc)

# Introduction

In this exercise, you'll learn how to populate Set [functions](https://docs.getxporter.app/space/XPORTERCLOUD/526934/Functions) while iterating Issue attachments.

# Populating Set Functions

> Macro (rw-ui-steps-macro)
> 
> > Macro (rw-step)
> 
> The Set function allows the creation of new variables that will be treated as fields ([mappings](https://docs.getxporter.app/space/XPORTERCLOUD/558575)) and <span style="color: #0d0d0d">modifies their values.</span>
> 
> The syntax to define a Set function is:
> 
> ```
> ${set(<variable name>,<new value>)}
> ```
> 
> > Macro (rw-step)
> 
> Create a Set function called *count* and in this case, <span style="color: #0d0d0d">initialize its value</span> to **zero**.
> 
> ```
> ${set(count,0)}
> ```
> 
> > Macro (rw-step)
> 
> If you want to display your attachments' iterations as a table with a header, first create the header using a table with three columns and one row:
> 
> | **Name** | **Size** | **Time** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> <span style="color: #0d0d0d">Beneath the header</span>, include the `#{for attachments}` or `#{for <VariableName>=AttachmentsCount}` statement <span style="color: #0d0d0d">to ensure the header is printed only once.</span>
> 
> > Macro (rw-step)
> 
> Redefine the variable *count* to increment by **one**. <span style="color: #0d0d0d">To achieve this, utilize the Set function again, but use the previous count value with JavaScript.</span>
> 
> ```
> ${set(count,%{${count} + 1})}
> ```
> 
> > Macro (rw-step)
> 
> Create another table where the Issue attachments will be populated:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Attachments[n].Name} | ${Attachments[n].HumanReadableSize} | ${dateformat("dd-MM-yyyy HH:mm:ss"):Attachments[n].Created} |
> 
> > Macro (rw-step)
> 
> To display the current iteration index, print the redefined variable using `${count}`
> 
> > Macro (rw-step)
> 
> Close the statement using the mapping `#{end}`
> 
> > ℹ️ This process can be applied to other types of [Iterations](https://docs.getxporter.app/space/XPORTERCLOUD/428318/Iterations).
> 
> ## Example
> 
> Below (Figure 1) is a sample of how the mappings will be displayed in a Word template.
> 
> ![image](media://730caeea-b08b-4054-b8bb-de741b804d75)
> 
> This Template (Figure 1) has:
> 
> - A header with a logo (Figure 1 - 1).
> - Headings (Figure 1 - 2).
> - Text styling (Figure 1 - 3).
> - Table (Figure 1 - 4).
> 
> Below (Figure 2) is a sample of how the generated file will be populated.
> 
> ![Figure 2 - Populated file](media://804ed430-7d13-4236-97f8-2590fcb2fa35)


> ℹ️ **This exercise is now complete. Proceed to **[**Exercise **](https://docs.getxporter.app/space/XPORTERCLOUD/430016)<span style="color: #0055cc">[**6**](https://docs.getxporter.app/space/XPORTERCLOUD/430016)</span>** to learn h****ow to populate the sum of worklog for all sub-tasks.**
> ℹ️ 
> ℹ️ 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 5 Resources</summary>

| **File** | **Description** |
| --- | --- |
|  | Exercise 5 - Sample Template file |
|  | Exercise 5 - 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>