Using Automation to Sum multiple custom fields

Matthew Pears
Contributor
February 26, 2022

Hello - I've set an automation rule to sum multiple numeric value custom fields. The automation rule worked perfectly when I was adding two fields, but when I included more fields that I wanted to sum, I received the error below. 

 

Screenshot 2022-02-26 113339.png

 

Here is the script in the Automation section: 

{{#=}}{{customfield_10112}} + {{customfield_10113}} + {{customfield_10114}} + {{customfield_10115}} + {{customfield_10116}} + {{customfield_10117}} + {{customfield_10118}} + {{customfield_10120}} + {{customfield_10121}} + {{customfield_10122}} + {{customfield_10123}} + {{customfield_10124}}{{/}}

Screenshot 2022-02-26 113625.png

Looking for guidance here. 

4 answers

1 accepted

2 votes
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2022

Hi @Matthew Pears ,

I could reproduce this behaviour in 3 ways:

  • adding a field that is not configured as numeric field
  • One of the custom fields of the calculation is not associated with the issue type/screen scheme
  • One of the fields in the calculation is empty

 

Hope this helps and helps solving the problem.

 

Best
Stefan

Matthew Pears
Contributor
February 26, 2022

Hi @Stefan Salzl 

Thanks for looking into this. I've checked all three items you mentioned, and everything seems to be correct. Still getting this error. 

Like vasanth likes this
Matthew Pears
Contributor
February 26, 2022

@Stefan Salzl UPDATE

I plugged values in all of the fields I am attempting to sum. This worked. However, I dont want the rule to behave this way, as some of the fields wont have values at the same time. 

So, how do I need to modify the code in my original message to reflect this? 

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2022

aaaah.....okay.

Guess the easiest way that comes to my mind would be to set default value '0'.

Would that be a feasible way?

 

Best
Stefan

Like # people like this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2022

Mainly the tough part of automation is to really be sure about the concrete use case/requirement, the specific conditions and specific action regarding use case and conditions. "random behaviour/conditions" is the opposite of automation.

Are there any special cases where it can be specified which of the fields should be filled and therefore summed up?

If this isn´t the case and all fields should always be summed regardless of value or not I would suggest to add the default value 0 as this is a identified as number and can be calculated. Otherwise the field is identified as empty which cannot be calculated.

Hope this helps.

Best
Stefan

Like # people like this
Matthew Pears
Contributor
February 26, 2022

@Stefan Salzl you're awesome. I set the default value to "0" which fixed my problem. The Automation works perfectly. 

However in trying to add a new rule on the same issue, I am trying to multiply two fields, and now I am seeing some strange behavior. The automation is working, but it is multiplying the last value in the field. For instance: 

Initial Value = 0

New Value = 5

New Value = 10

Where I would expect the rule to multiply the fields first new value (5), but it does not. However when I change the fields value to 10, then it finally multiplies by now the old value 5. 

I need it to multiply the "newest value" in the field. 

{{#=}}{{customField_10125}} * {{customField_10126}}{{/}}

 

Screenshot 2022-02-26 171159.png

Like Caio Cesar Covos likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2022

AAAWESOME!!! Happy it works. You rock 💪

I would need more context here. Could you provide a screenshot of the field and name

  • which field gets updated (that triggers the rule)
  • which fields should then be multiplied and
  • which field should then be updated with the result

BTW: You could also use the name of the field instead of the field_ID in smart values. That makes it easier to read and understand automation rule (especially for me as a reader) 😉

 

Best
Stefan

Caio Cesar Covos January 18, 2023

Hello guys,

Is it possible to use this script to calculate using Asset attribute?

Ex.

Field 1: Worked hours (Number Field);
Field 2: Cost of the hour (Jira Asset);

Field 3: Total cost (Number Field)

(Field 3 = Field 1 * Field 2)

 

Thanks

Iryna Komarnitska_SaaSJet_
Atlassian Partner
January 19, 2023

Hi @Caio Cesar Covos 

Try to use add-on , developed by my team - Cost Tracker for Jira Cloud .

It multiple People logs to People rates per hour, and you can generate reports with this data. Also, the Cost Tracker for Jira Cloud add-on allows you to track all your company's expenses.

It's free.

Example of report:

cost  report.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.
January 19, 2023

Hi @Caio Cesar Covos -- Welcome to the Atlassian Community!

Yes, you may perform a calculation like that in an automation rule.  I recommend triggering it on a change to any of those three fields, including the result.  (That will handle the case of someone altering it.)

Please look here for more information on such field calculations in rules: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-math-expressions/

Kind regards,
Bill

Like # people like this
4 votes
Corwyn Tomashewski
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 4, 2023

I'm Running JSM DC 5.6.0, but on my installation something like this works really well:

{{#=}}{{customfield_10112|0}} + {{customfield_10113|0}} + {{customfield_10114|0}} + {{customfield_10115|0}} + {{customfield_10116|0}} + {{customfield_10117|0}} + {{customfield_10118|0}} + {{customfield_10120|0}} + {{customfield_10121|0}} + {{customfield_10122|0}} + {{customfield_10123|0}} + {{customfield_10124|0}}{{/}}

If you append the "|0" to the end of the custom field identifier, the sum will take the value as zero if the field is NULL. That should get rid of your error!

Definitely make sure all the fields you're summing are numerical fields only though.

Best regards,
Corwyn

Bob Griffin August 21, 2024

Thanks for the idea. That worked for me also.

Like Stefan Salzl likes this
2 votes
Andreas Knecht
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 2, 2022

Please note that you can also use default values for smart-values. See the bottom of https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/

 

Something like this should work: {{customfield_22222|0}} (note the |0 at the end)

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 2, 2022

I was sure there is something like

this but couldn‘t find the hint. That‘s awesome. Thanks so much 🙌🏼👌🏼

Like Matthew Pears likes this
0 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.
February 28, 2022

Hi @Matthew Pears 

Have you checked if your custom field's types are text or numeric?

If text, you may need to convert them to numbers in order to make a mathematical function work, such as:  {{issue.myCustomField.asNumber}}

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer