Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Create a Calculating Form

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 or edit a form

How AFJ works
Smart values

Workaround steps:

  • Form Settings:

    • 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.

    • It will need to link all form fields to custom Jira fields (this is necessary for the A4J to be able to get the answers from the fields):Screen Shot 2022-12-23 at 11.18.43.png

       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)

    • And it will be necessary to leave the form open on issue creation (this is necessary for having communication between Jira Forms and the A4J):Screen Shot 2022-12-23 at 11.25.28.png
  • Create a Looping Transition:
    • 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.Screen Shot 2022-12-23 at 11.36.36.png
      Note: This will create a "Calculate button":Screen Shot 2022-12-23 at 11.41.10.png

       For more details about looping transitions, please refer to How to create global looping transitions in a Jira workflow
  • Build the Automation Rule:

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

       

      Screen Shot 2022-12-23 at 12.41.19.png
    • 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):

3 comments

Elspeth Kelly December 23, 2022

This is great @Bruno Altenhofen ! Thank you for sharing this!!!

Like Bruno Altenhofen likes this
Jamie MacDonald January 24, 2023

Thanks for sharing this. I am excited to try this out in place of more complicated Scriptrunner scripts.

Like Bruno Altenhofen likes this
Bruno Altenhofen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 27, 2023

Hey @Jamie MacDonald
Thanks for the feedback, I really appreciate it!! :D

Like Jamie MacDonald likes this

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events