Jira smart value does not show decimal number

Eduardo Lima March 7, 2024

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>



1 answer

1 accepted

0 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 9, 2024

Hi @Eduardo Lima 

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

Eduardo Lima March 12, 2024

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

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2024

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.

Eduardo Lima March 12, 2024

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:

Screenshot 2024-03-12 at 13.28.27.png

 

And below you can see the result from the

<h4>BILL</h4>
{{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}}

Screenshot 2024-03-12 at 13.30.38.png

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

 

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2024

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){{/}}

 

Eduardo Lima March 12, 2024

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.

 

Screenshot 2024-03-12 at 17.01.48.png

 

Regards,

Eduardo

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2024

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.

Eduardo Lima March 13, 2024

Hi @Bill Sheboy ,

Here are the screenshots:

Screenshot 2024-03-13 at 09.17.29.png

 

Screenshot 2024-03-13 at 09.18.10.png

Even though the output is 0, the sum would be in seconds and I still would need to divide it by 3600.

Regards,

Eduardo

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2024

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.

Eduardo Lima March 13, 2024

Here you go!

Screenshot 2024-03-13 at 11.29.44.png

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2024

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:

  • trigger: scheduled, with no JQL
  • action: lookup issues, with the JQL just removed from the trigger
  • action: log your total sum
Sum: {{#=}}ROUND(0{{lookupIssues.aggregatetimespent.sum}} / 3600, 2){{/}} hours
  • action: log each value with its issue key
Each entry: {{#lookupIssues}}{{key}}: {{#=}}ROUND(0{{aggregatetimespent}} / 3600, 2){{/}} hours; {{/}}

 

Eduardo Lima March 13, 2024

Hello @Bill Sheboy ,

Your solution is beyond perfection!! Thank you very much.

Here are the code and the results:

Screenshot 2024-03-13 at 14.09.17.png

Results:

Screenshot 2024-03-13 at 14.08.14.png

I will use your solution in the Weekly Report sent by email.

I'm so grateful, thank you.

Eduardo

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events