I want to add the worklog from JSM to the worklog from JS to get a total time spent
Asked by Warren Turner:

Hi!

I hope someone might be able to answer a puzzling scenario.

I am trying to create a manually run automation rule that provides me a sum total across linked issues so we can see how much time is spent by both the SD Agents and the 3rd line Support team for completing an issue. Our Account team would like to be able to do this with the click of a button in JSM instead of having to export to csv, then manipulate the output to give the total.

This should catch all "causes" issues if there are more than one.

I can get the worklog.timespentseconds from JSM

{{issue.worklog.timeSpentSeconds}}

I can get the worklog of {{issuelinks.outwardIssue.worklog.timespentseconds}}

The automation log shows this:

##### [Log action](https://tsoltd.atlassian.net/jira/settings/automation#/rule/6747266/127503660) {#toc-hId--1647900738}

Log  
Time on SD issue: 3600  

##### [Log action](https://tsoltd.atlassian.net/jira/settings/automation#/rule/6747266/127503662) {#toc-hId-839612095}

Log  
Time on Linked issues out: \[7200\], \[10800\]  

##### [Log action](https://tsoltd.atlassian.net/jira/settings/automation#/rule/6747266/127503663) {#toc-hId--967842368}

Error rendering smart-values when executing this rule:  
Token is empty: Total time spent across all linked issues: {{#}}{{sdissuetotal}} + {{outwardissuetotal}} / 3600{{/}}

When I amend the second smart value to {{issuelinks.outwardIssue.worklog.timespentseconds.sum}} I get no value.

##### [Log action](https://tsoltd.atlassian.net/jira/settings/automation#/rule/6747266/127502885) {#toc-hId-1519670465}

Log  
Time on SD issue: 3600  

##### [Log action](https://tsoltd.atlassian.net/jira/settings/automation#/rule/6747266/127502887) {#toc-hId--287783998}

Log  
Time on Linked issues out:  

##### [Log action](https://tsoltd.atlassian.net/jira/settings/automation#/rule/6747266/127502888) {#toc-hId--2095238461}

Error rendering smart-values when executing this rule:  
Token is empty: Total time spent across all linked issues: {{#}}{{sdissuetotal}} + {{outwardissuetotal}} / 3600{{/}}

My expectation was this would return an 18000 summed total second value. At that point I could simply add them and divide by 3600 to get minutes spent total.

I referred to this previous question:

<https://community.atlassian.com/t5/Automation-questions/How-to-get-sum-timespent-from-linked-issues/qaq-p/1471579>

but for some reason the sum doesn't add the array values as expected to provide a total linked issue value which I can then add to the JSM total.

Does anyone have any ideas on how to solve this? Or is it a bug in the sum function that the A4J team need to address?

Thanks in advance

Warren


Answers:
author: Bill Sheboy
body: Hi [@Warren Turner](/t5/user/viewprofilepage/user-id/1984616)

To provide some context, would you please post images of your complete rule, details of the summation/edit components used, and of the audit log details showing the rule execution? Thanks!

Kind regards,  
Bill

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

Thanks for taking the time to look at my query.

This is the rule and the two variables I am checking in the log:

![rule and variable details.png](https://community.atlassian.com/t5/image/serverpage/image-id/203264i6773881AD4BCFC1F/image-size/large?v=v2&px=999 "rule and variable details.png")

And this is the result of the two different smart value returning the results.

The first image shows it producing the worklogs second values, which seems to be as an array of values, when I don't use the .sum on the outward issue variable.

The second one shows an empty result when I add the .sum to aggregate the values into a total seconds amount

![audit log.png](https://community.atlassian.com/t5/image/serverpage/image-id/203266i94299ECD1A8440C1/image-size/large?v=v2&px=999 "audit log.png")

Thanks

Warren


author: Warren Turner
body: This is the variable tweaked with the .sum added to which produces the second log above. Its weird as I thought the aggregate would simply add value 1 to value 2 to produce the sum total of the worklog, and then I can simply add the two and then divide to get total mins! Logically it seems sound but I am hitting a brick wall.

![with .sum option.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/203268i80C0D69857D50C21/image-size/large?v=v2&px=999 "with .sum option.PNG")


author: Bill Sheboy
body: I wonder if that time value is text (because of possible units of measure). Perhaps try adding .asNumber.sum to convert before summation.

Also, smart values are case-sensitive, and I note you made that one all lower case. Perhaps try making it match your first variable and the documentation: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--worklog-->

Unfortunately when we enter invalid smart values in a rule, they often just collapse to null rather than showing an error.


author: Warren Turner
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Thanks for you input. I eventually managed to get it to work :-)

For those who may be interested this is how I did it:

{{issue.timetracking.timeSpentSeconds.plus(issuelinks.outwardIssue.timetracking.timeSpentSeconds.sum)}}

<br />

This basically takes the current issues time tracking logs and adds it to the linked issues totals to get a sum of seconds across all items.

I simply then cast that into hours as a new variable thus:

{{#=}}{{currenttotal}} / 3600{{/}}


Tags: issue-link

worklog