---
title: "Exercise 6 - Populating the Sum of Worklog"
canonical: "https://docs.getxporter.app/space/XPORTERCLOUD/430016/Exercise%206%20-%20Populating%20the%20Sum%20of%20Worklog"
format: markdown
---
> Macro (rw-ui-expands-macro)
> 
> > Macro (rw-expand)
> 
> > Macro (toc)

# Introduction

In this exercise, you'll learn how to populate the sum of the worklogs for all subtasks.

## Populating the Sum of Worklog for All Subtasks

> Macro (rw-ui-steps-macro)
> 
> > Macro (rw-step)
> 
> Create a Set function to establish a variable called *sumworklogged* and set its initial value to **zero**.
> 
> ```
> ${set(sumworklogged,0)}
> ```
> 
> > Macro (rw-step)
> 
> To display your iteration as a table with a header, you must first create the header using a table with three columns and one row:
> 
> | **Key** | **Time Spent** | <span style="color: #000000">**Sum Time Spent**</span> |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Below the header, include the `#{for subtasks}` or `#{for <VariableName>=SubtasksCount}` <span style="color: #0d0d0d">to ensure the header is printed only once. </span>
> 
> > ℹ️ *SubtasksCount* <span style="color: #0d0d0d">returns the number of subtasks in the Issue being exported.</span>
> 
> > Macro (rw-step)
> 
> Inside the subtasks iteration, create another iteration for the [worklogs](https://docs.getxporter.app/space/XPORTERCLOUD/428318/Iterations#Iterating-Issue-Worklogs) to print the time spent on all subtasks in the Issue.
> 
> > Macro (rw-step)
> 
> Insert the `#{for s=Subtasks[n].WorklogsCount}` statement.
> 
> > Macro (rw-step)
> 
> Create another table where the Subtask Issues worklogs will be populated:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Subtasks[n].Key} | %{Number(${Subtasks[n].Worklogs[s].Time Spent})/3600} | ${set(sumworklogged,%{(Number(${Subtasks[n].Worklogs[s].Time Spent})/3600) + Number(${sumworklogged})})}${sumworklogged} |
> 
> > ℹ️ - The second column is going to give the Time Spent in hours.
> > ℹ️ - The third column is going to give the sum of Time Spent in hours.
> > ℹ️ - When entering each iteration, the Time Spent will be summed with the value from the last iteration. On the very first iteration, that value is zero.
> 
> > Macro (rw-step)
> 
> Close the two statements using the mapping `#{end}`
> 
> > ℹ️ You've only got the worklogs from the subtasks.
> 
> > Macro (rw-step)
> 
> Retrieve the worklog of the main Issue and calculate the total logged work of the Issue with its subtasks.
> 
> > Macro (rw-step)
> 
> Create the header using a table with three columns and one row:
> 
> | **Key** | **Time Spent** | **Sum Time Spent** |
> | --- | --- | --- |
> 
> > Macro (rw-step)
> 
> Below it, include the `#{for worklogs}` or `#{for <VariableName>=WorklogsCount}` <span style="color: #0d0d0d">statement to ensure the header is printed only once.</span>
> 
> > Macro (rw-step)
> 
> Create another table where the Issue worklogs will be populated:
> 
> |  |  |  |
> | --- | --- | --- |
> | ${Key} | %{Number(${Worklogs[n].Time Spent})/3600} | ${set(sumworklogged,%{(Number(${Worklogs[n].Time Spent})/3600) + Number(${sumworklogged})})}${sumworklogged} |
> 
> > Macro (rw-step)
> 
> Close the statement using the mapping `#{end}`
> 
> > ℹ️ - Ensure that you have created an Issue of type *Story* and added subtasks to it.
> > ℹ️ - Time tracking must be configured on your project, and there must be logged work on the Issue to export and/or its subtasks.
> 
> Examples
> 
> Below (Figure 1) is a sample of how the [mappings](https://docs.getxporter.app/space/XPORTERCLOUD/558575) will be displayed in an [Excel template](https://docs.getxporter.app/space/XPORTERCLOUD/558471).
> 
> ![Figure 1 - Excel template](media://83d72795-7a89-42fa-85ae-b0199611cc6c)
> 
> This Template (Figure 1) includes:
> 
> - Headings (Figure 1 - 1).
> - Text styling (Figure 1 - 2).
> 
> Below (Figure 2) is a sample of how the generated file will be populated.
> 
> ![Figure 2 - Populated file](media://173d9861-5be5-498e-97df-d2ef85045e5d)


> ℹ️ **This exercise is now complete. Proceed to **[**Exercise 7**](https://docs.getxporter.app/space/XPORTERCLOUD/559560/Exercise+7+-+How+to+Populate+Details+of+Images)** to learn h****ow to populate details of images.**
> ℹ️ 
> ℹ️ 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 6 Resources</summary>

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