Automation smart values list does not sum at all
Asked by Piotr Intres:

Hi there,

I am struggling with following issue:  

I have two projects - let's call them SCRUM and DEPLOYMENT.

Issues (stories/bugs/tasks/) I am cloning and moving from SCRUM project to DEPLOYMENT project.  
Let's think of SCRUM story - called SCR-1 (+5 subtasks) and cloned story DEP-1. Both stories are related by "clones" relation. From the level of DEP-1 I need to collect all the time spent on SCR-1 (together with the subtasks) and put them as sum into a custom field.

**Now as used in automation** (printing as issue comment for debug purpose):

1.  

{{issue.issuelinks.outwardIssue.sub-tasks.timetracking.timespentseconds}}

returned value:   
\[11040, 5820, 0, 900, 31440\]

2.

{{issue.issuelinks.outwardIssue.sub-tasks.timetracking.timespentseconds.sum}}

returned value:   
\<no value\>

3.

{issue.issuelinks.outwardIssue.sub-tasks.timetracking.timespent}}

resulted value:  
\[3h 4m, 1h 37m, 0m, 15m, 1d 44m\]

**Please mind the difference at the last position!!** It should be 8h 44m (and that what Tempo is showing on that issue).

4.   

{{issue.issuelinks.outwardIssue.sub-tasks.timetracking.timespent.sum}}

returned value:   
\<no value\>

**Questions**:

1. Why there is a difference on the last position of that array when the value of TimetrackingBeam is correct:

TimetrackingBean{originalEstimate='1h', remainingEstimate='0h', timeSpent='8.73h', originalEstimateSeconds=3600, remainingEstimateSeconds=0, timeSpentSeconds=31440}  

2. Why I can't sum up any of them as a list? It at least should be possible with the Seconds.

3. Is there any other way to achieve what I need?  


Answers:
author: Bill Sheboy
body: Hi [@Piotr Intres](/t5/user/viewprofilepage/user-id/5589627) -- Welcome to the Atlassian Community!

Without seeing the details of your automation rule and the audit log for the rule execution...

Those two time tracking smart values have different purposes:

* {{issue.timetracking.timeSpent}} is the "pretty print" one, making it human-readable. And thus it is text type.
* {{issue.timetracking.timeSpentSeconds}} is the seconds only, making it helpful for math. It is a number with no units identifier (of seconds).

I recommend using timeSpentSeconds for your scenario.

Next, you are referencing *nested lists of things*: subtasks within linked issues and linked issues within the original issue. When that happens, you observe the array format with the square brackets inside of the outer list items. Also leading to some empty \[\] cases.

And...the {{issue.issuelinks}} smart value is impacted by the direction of links, leading some entries having inner, outer, or both types in the list.

Finally, the {{issue.subtasks}} smart value is dynamic, loading the data just in time. If it did not you could imagine a cross-linked issue scenario that would attempt to load many issues (through links and subtasks) when the rule starts!

There are two possible fixes for those things: use dynamic JQL to load all the subtasks with Lookup Issues to sum or use [list iteration](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#Combined-function-examples) and [math operations](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/) to join the values together for summation...where the key is iterating over the correct thing and adding 0 defaults as needed.

{{#=}}0 {{#issue.issuelinks.outwardIssue}}+0{{subtasks.timetracking.timeSpentSeconds.join(" +")}}{{/}} {{/}}

The expression above iterates over any outwardIssue links found, and then joins together any time tracking values for any subtasks found. The whole thing is wrapped in a math expression, with a zero default at the front, to give a total number of seconds.

Kind regards,  
Bill

comments: author: Piotr Intres
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Thank you very much for your answer - it worked as a charm.

Kind regards,

Piotr


Tags: cloud

jira-cloud