Hello,
I am writing an Jira Automation to send and Email with the sum of Time Spent logged in Sub-tasks.
I can see the correct values using smart value {{aggregatetimespent}} but it comes in seconds.
I just need to divide it by 3600 to have these values in hours, but the expression below only returns the round number and I would like the decimal number.
{{aggregatetimespent.divide(3600)}}
Expected: 15300 / 3600 = 4.25
Actual result: 15300 / 3600 = 4
Any suggestion?
Here is the complete code:
<h1>Weekly Report</h1>
<h3>
Total of {{lookupIssues.size}} issues Resolved this week.
</h3>
<h3>
Velocity = {{lookupIssues.Story Points.sum}} Story Points
</h3>
<h3>
Time Spent = {{lookupIssues.timetracking.timespentseconds.sum.divide(3600)}} hours. (sem round)
</h3>
<table border="0" cellpadding = "3" cellspacing = "1">
<tr>
<th>Ticket Id</th>
<th>Status</th>
<th>Issue Type</th>
<th>Summary</th>
<th>Resolved date</th>
<th>Story Points</th>
<th>Time Spent</th>
</tr>
{{#lookupIssues}}
<tr>
<td><a href="{{url}}">{{key}}</a></td>
<td>{{status.name}}</td>
<td>{{issueType.name}}</td>
<td>{{summary}}</td>
<td>{{resolved.mediumDate}}</td>
<td>{{Story Points}}</td>
<td>{{aggregatetimespent.divide(3600)}}</td>
</tr>
{{/}}
</table>
I suspect this behavior happens because the smart value aggregatetimespent is dynamically calculated or its typing is integer-only.
A work-around is to use a math expression, as shown below:
{{#=}}ROUND({{aggregatetimespent}} / 3600, 2){{/}}
I added the ROUND() function to limit the number of digits after the division: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Functions
Kind regards,
Bill
Hello @Bill Sheboy
Thank you for your answer.
I tried your solution but got the following error message:
I updated my code with your solution:
<h4>BILL</h4>
{{#=}}ROUND({{aggregatetimespent}} / 3600, 2){{/}}
And got the following message:
Action details:
Lookup issues
A search during custom value definition found no issues.
Send email
Error rendering smart-values when executing this rule:
Unknown unary operator / at character position 8: ROUND( / 3600, 2)
FYI, I've found a bug opened for the same kind of error. See link below:
https://jira.atlassian.com/browse/AUTO-407
It seems this problem has been around on since 2021 :(
Regards,
Eduardo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your lookup has no results and that is why there is no value and the expression leads to an error. A work-around would be to add a default value of 0:
{{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}}
But I am puzzled: what is the structure of your expression that it iterated over the lookup when there were no issues? Please post the complete expression which uses that math operation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy ,
I am trying to create an Automation to send an email with a list of the completed issues and the Sum of Time Spent (including Sub-tasks).
Smart Value {{aggregatetimespent}} provides that sum, but in seconds.
You were right when you said "there are no values in some cases". This is due to the fact that some tickets do not have Time Spent hours logged :)
Following your suggestion, I have defaulted "0" but the results are still ugly.
This is the code
<table border="0" cellpadding = "3" cellspacing = "1">
<tr>
<th>Ticket Id</th>
<th>Status</th>
<th>Issue Type</th>
<th>Summary</th>
<th>Resolved date</th>
<th>Story Points</th>
<th>TS seconds</th>
<th>TS hours</th>
</tr>
{{#lookupIssues}}
<tr>
<td><a href="{{url}}">{{key}}</a></td>
<td>{{status.name}}</td>
<td>{{issueType.name}}</td>
<td>{{summary}}</td>
<td>{{resolved.mediumDate}}</td>
<td>{{Story Points}}</td>
<td>{{aggregatetimespent}}</td>
<td>ROUND(0{{aggregatetimespent}} / 3600, 2)</td>
</tr>
{{/}}
</table>
<h4>BILL</h4>
{{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}}
This is a fragment of the email produced by the Automation:
And below you can see the result from the
<h4>BILL</h4>
{{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}}
PS. Unfortunately, due to this bug in Jira, I am running out of Automations and I need to wait until next April, 2024 to start testing again :(
I appreciate very much your dedication.
Regards,
Eduardo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing, some tips when creating / testing automation rules:
Back to your rule...I see this in your expression
{{#lookupIssues}}
<tr>
<td><a href="{{url}}">{{key}}</a></td>
<td>{{status.name}}</td>
<td>{{issueType.name}}</td>
<td>{{summary}}</td>
<td>{{resolved.mediumDate}}</td>
<td>{{Story Points}}</td>
<td>{{aggregatetimespent}}</td>
<td>ROUND(0{{aggregatetimespent}} / 3600, 2)</td>
</tr>
{{/}}
The bolded section is incorrect, and instead should include the math expression wrapper:
{{#lookupIssues}}
<tr>
<td><a href="{{url}}">{{key}}</a></td>
<td>{{status.name}}</td>
<td>{{issueType.name}}</td>
<td>{{summary}}</td>
<td>{{resolved.mediumDate}}</td>
<td>{{Story Points}}</td>
<td>{{aggregatetimespent}}</td>
<td>{{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}}</td>
</tr>
{{/}}
And for the last section, did you want the total for the entire lookup result? If so, please try this:
<h4>BILL</h4>
{{#=}}ROUND(0{{lookupIssues.aggregatetimespent.sum}} / 3600, 2){{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy ,
Thank you for educating me in this process.
Using "Log an Action" is really useful.
As you can see from the picture below, TS worked like a charm, thank you very much!
But the ".sum" did not return the expected value.
TS: {{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}}
Sum: {{#=}}{{lookupIssues.aggregatetimespent.sum}}{{/}} seconds.
Total TS = {{#=}}ROUND(0{{lookupIssues.aggregatetimespent.sum}} / 3600, 2){{/}} hours.
Regards,
Eduardo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Context is important for automation rules. Please post an image of the complete rule which contains those writes to the audit log.
Those last two entries you show cannot be inside of the lookup issues iterator because they span the entire lookup. If they are, I would expect them to return nothing.
Also, for this one:
Sum: {{#=}}{{lookupIssues.aggregatetimespent.sum}}{{/}} seconds.
The only math operation is the sum, and so it does not need to be enclosed in the math expression notation. Please try this instead:
Sum: {{lookupIssues.aggregatetimespent.sum|0}} seconds.
That will provide the sum, with a default value of 0 when there is no time spent.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy ,
Here are the screenshots:
Even though the output is 0, the sum would be in seconds and I still would need to divide it by 3600.
Regards,
Eduardo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Understood, and so that expression does need the math expression to support the division.
When I asked for an image of the complete rule, I wanted to see all of the rule steps in one image. That will show the order of actions relative to where those writes to the log are happening.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah...there is no Lookup Issues action, and so there will be no data for that second write to the audit log.
Please try this for that rule:
Sum: {{#=}}ROUND(0{{lookupIssues.aggregatetimespent.sum}} / 3600, 2){{/}} hours
Each entry: {{#lookupIssues}}{{key}}: {{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}} hours; {{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Bill Sheboy ,
Your solution is beyond perfection!! Thank you very much.
Here are the code and the results:
Results:
I will use your solution in the Weekly Report sent by email.
I'm so grateful, thank you.
Eduardo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.