Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

custom fields and calculating the average of two scores

Mariko Kelly November 9, 2022

Hi, I'm trying to use automation to calculate the average of 2 custom fields and populate that answer in a 3rd custom field.

 

I would like to do:

Average = ((I Score) x (F Score)) / 2  

 

This is currently the query I'm using: 

{{#=}}{{issue.I Score}} + {{issue.F Score}} / 2 {{/}}

 

I have two questions: 

1) when I use this formula, it just divides F Score by 2 - when I try to use parentheses for order of operations I get an error message. Any suggestions?

2) I would like the answer to round to the nearest whole number - how would I use the round functionality in this query?

 

Thank you! 

1 answer

3 votes
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.
November 9, 2022

Hi @Mariko Kelly -- Welcome to the Atlassian Community!

I wonder if this is related to the types of your fields.  Are they both number fields, or something else?

And when you note using parentheses leads to an error, would you please show what you tried?

Another way to do this is to chain the operations, and add round to the end, such as this:

{{issue.I Score.plus(issue.F Score).divide(2).round}}

This format may reveal that the fields' smart values to not match what you expect.  Those are name, spacing, and case-sensitive.  One way to check the smart values is to use this how-to article's guidance: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

Kind regards,
Bill

Mariko Kelly November 10, 2022

Hi @Bill Sheboy

Thank you so much for your quick response / help!

{{issue.I score.plus(issue.F Score).divide(2).round}}

So, I ended up using your chain of operations and I validated that the fields' smart values are the same as I inputted.

 

Now, the automation is successful, but it doesn't output anything. I've shared some screenshots here - the output field is "Total Score" 

 

 

Screen Shot 2022-11-10 at 5.17.24 PM.png

 

 

Screen Shot 2022-11-10 at 5.16.50 PM.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.
November 11, 2022

Let's try the simplest thing first...

The issue created trigger can fire before all of the issue fields are available to a rule.  To slow down a rule and reload the data, please add the Re-fetch Action immediately after the trigger and then retest your rule.

Also...can the "I Score" and "F Score" fields change later, after an issue is created?  If so, you may need a second rule triggered on changes to those fields to recalculate the "Total Score".

Mariko Kelly November 11, 2022

Hi @Bill Sheboy

I added the Re-fetch Action immediately after the trigger and the audit log said it was a success, however, it still is not populating any information in the Total Score field :( Is there anything else I can try? 

I also double checked that all the custom fields are number fields... 

Thank you so much for all of your help - I really appreciate it!

 

Screen Shot 2022-11-11 at 9.51.50 AM.png

Mariko Kelly November 11, 2022

Hi @Bill Sheboy

I was able to resolve this, almost!

I ended up using the following - this populated the a score into Total score, as expected/wanted: 

{{#=}} ({{issue.I score}}/2) + ({{issue.F Score}}/2) {{/}}

 

However, when I try to use the round function, 

{{#=}} round(({{issue.I score}}/2) + ({{issue.F Score}}/2)) {{/}} 

I receive this error message in the audit log:

Error rendering smart-values when executing this rule:
Function round expected 2 parameters, got 1: round((2/2) + (5/2))


Any thoughts on what I'm doing wrong with this?

Thank you so much! 
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.
November 11, 2022

Well done, and...

When using that syntax for ROUND it takes a value and a precision: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/#Functions

Please try this:

{{#=}} ROUND(({{issue.I score}}/2) + ({{issue.F Score}}/2), 0) {{/}} 
Mariko Kelly November 13, 2022

That worked! Thank you so much for all of your help @Bill Sheboy

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events