Different from 'Add Issue Score for Jira by calculating choice fields' which explains how to calculate text and choices fields and add a score at the end, here I explain how to calculate number fields and leave a total value. So this is an option of the workaround from the feature JRACLOUD-61966 and is meant to help projects where it is necessary to calculate a sum of numbers and report the total. In this documentation, I used Jira Forms with Automation For Jira(A4J). Also, I used as an example a form related to a purchase from a store in which it calculates the number of items, multiplies the values according to the number of selected items, adds them to the fees provided, and then informs the total of the purchase. This method can be used for other purposes (eg. general and administrative costs).
Important related documentation:
Create a custom field (number) for each item that will be used in the calculation, as well as for each field that will hold the result of a calculation.
For more information, please refer to the documentation Link a form field to a Jira field.
For fields that will hold calculated values, you can use the description property to tell the user/customer that they do not fill out the field. (Jira Forms does not currently have read-only fields: JSDCLOUD-10701 - Form Field: Read only fields)
If your form will include nested calculations (for instance if you want to calculate a subtotal that is then used in a calculation of the grand total), then you will need a status change to trigger each calculation. A looping transition allows you to trigger the form to recalculate.
Note: This will create a "Calculate button":
For more details about looping transitions, please refer to How to create global looping transitions in a Jira workflow
Use the Edit issue fields action to perform the calculation. You will need to reference the custom field ID in the rule, in this example I used the multiplication of the items and then their sum to calculate the subtotal:
{{#=}}{{issue.customfield_10104}}*{{issue.customfield_10109}}+{{issue.customfield_10105}}*{{issue.customfield_10110}}+{{issue.customfield_10106}}*{{issue.customfield_10111}}{{/}}
So the icing on the cake for calculating the total is to put the Subtotal on the end of the smart value order (This is because there is a timing issue on the automation rule, as the Subtotal is still being calculated and does not have the value to be added in the Edit action of the Total):
{{#=}}{{issue.customfield_10115}}+{{issue.customfield_10116}}+{{issue.customfield_10114}}{{/}}
The customfield_10114 is the Subtotal field. To find the custom field ID please take a look at this documentation.
This workaround will work as shown in the screen recording below (note that it will always be necessary to refresh the page to give A4J enough time to execute the automation rule and the attached form must be open for the calculation to happen):
Bruno Altenhofen
Atlassian Engineer - The guy from Proforma(Jira Forms)
e-Core
Krakow - Poland
1 accepted answer
3 comments