Add predefined values and create a Calculation Form with Assets

Following the same logic from 'Create a Calculating Form' which explains how to calculate form number fields and make the sum of the values at the end, here I'll explain how to calculate fields with a predefined value and leave a total value. So this is an option of the workaround from the features below:

 

And is meant to help projects where it is necessary to calculate a sum of numbers that was linked to a product or object and report the total. In this documentation, I used Jira Forms with Automation For Jira(A4J) and Assets. Also, I used as an example a form related to an order purchase from a store in which the products have predefined prices. So it will calculate the number of items, multiplies the values according to the number of selected items, add 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
Set up the Assets objects custom field

Workaround steps:

  • Crete Assets objects schemas

    • Create object schemas for each item that will be used, as well as for each option that will be used on the cascading logic, for my example I used: Product and Prices.

    • It will need to link an object 'Product' to an object 'Price' as an attribute. In short, you will be adding a price to this product:

     

  • Product:
    Screenshot 2023-04-03 at 16.15.42.png
  • Price(Note that, for this workaround, the object name will be the price value):
    Screenshot 2023-04-03 at 16.17.53.png
     Remember to mark the option "Allow others to select objects from this schema". For more details about object schemas, please refer to Create an object schema
  • Create Assets objects custom fields

    • Create a custom field (assets) for each option that will be used in the cascading values, I created the field "Apple Product" and "Apple Product Price".

    • It will need to use the Filter issue scope (AQL) to reference the object custom field in the order of your cascading logic. In this example: Apple Product > Apple Product Price

      Using the AQL:
      object HAVING inboundReferences(Name = ${customfield_XXXX.label})
  •  Apple Product(I have 6 Apple products, so 6 Assets objects fields for each  one):

    • Screenshot 2023-04-03 at 16.42.24.png


    • Screenshot 2023-04-03 at 16.43.35.png

  • Apple Product Price:

    • Screenshot 2023-04-03 at 16.44.59.png


    • Screenshot 2023-04-03 at 16.46.20 1.png

 Remember to mark the option "Display a default object when this field appears in a customer portal" to the refered field objects. For more details about object schemas, please refer to What is the Assets objects field?

  • Form Settings:

    • Create an Asset object field 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):
      Screenshot 2023-04-03 at 17.02.29.png

       For more information, please refer to the documentation Link a form field to a Jira field.
    • Extra tip: You can use conditional logic to better organize your purchase order. In this example, I created a field to select how many products the order will have, and depending on the answer, it will open the necessary lines to fill in the number of products. For more information, please refer to the documentation Add a conditional field to your project using Forms.

  • 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 with the Assets object custom field in the rule, in this example I used the multiplication of the items and then their sum to calculate the subtotal:

      {{#=}}{{issue.customfield_10104|0}}*{{issue.customfield_10169.Name|0}}+{{issue.customfield_10105|0}}*{{issue.customfield_10175.Name|0}}+{{issue.customfield_10106|0}}*{{issue.customfield_10176.Name|0}}+{{issue.customfield_10106|0}}*{{issue.customfield_10177.Name|0}}+{{issue.customfield_10107|0}}*{{issue.customfield_10178.Name|0}}+{{issue.customfield_10205|0}}*{{issue.customfield_10179.Name|0}}{{/}}

       

      Screenshot 2023-04-03 at 17.42.02.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|0}}+{{issue.customfield_10116|0}}+{{issue.customfield_10114|0}}{{/}}
       The customfield_10114 is the Subtotal field. To find the custom field ID please take a look at this documentation.
      Also, the "|0" smart value is necessary to put a "callback" value if the field is blank. So it will return the value 0 and it will not give you an error in your automation rule. 

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

Bruna Silva
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2023

Great! :D

Like Bruno Altenhofen likes this
Charles Trilha
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2023

Amazing! :)

Like Bruno Altenhofen likes this
Anthony Morais
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.
June 15, 2023

Amazing! 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events