Need to calculate a value in a field from two other fields
Asked by Kathy Dickason:

I have these fields with numerical values:

* Total Points
* Total Resolved Points
* Total Unresolved Points

I would like to auto-populate another field named Percent Completed by dividing Total Resolved Points by Total Points then multiplying by 100. Can you tell me what type of field to create to house this and how to populate it with a formula to show the Percent Complete? I have ScriptRunner but no other plug-in. I am not a developer and cannot code, so really need help.


Answers:
author: Marc - Devoteam
body: Hi [@Kathy Dickason](/t5/user/viewprofilepage/user-id/3909439)

You can create an automation rule and have an edit action the looks like:

{{#=}}{{issue.Total Resolved Points}} / {{issue.Total Points}} \* 100{{/}}

comments: author: Kathy Dickason
body: Okay, this (above) worked for my Epic % Complete field. Thank you! Here's my next problem, however:

This automation runs when a story is updated. When the story is updated to add an Epic Link, the story points from it are added to the field Total Points field on the Epic screen for the Epic it is linked to). This works great, except in the circumstances when someone changes the Epic Link on the Story or deletes the Epic Link from the Story. When that happens, the Lookup issues portion of the Automation no longer can find the Epic the story was assigned to (since it changed) so the story point total in the Epic remains at the same number even though the story is no longer linked to it.

I can fix this by going into one of the stories that is still assigned to the Epic and making any kind of update to the form, which triggers the rule and point calculation again. But when I try to automate this (add then remove a label to every story, for instance, via automation), the update to the issue doesn't trigger the rule calculation. Why does an automated update not work, but a manual update does? Any ideas on what I can do?

![epic_link_automation.png](https://community.atlassian.com/t5/image/serverpage/image-id/336119iB6A089EE61E92BF1/image-size/large?v=v2&px=999 "epic_link_automation.png")


author: Kathy Dickason
body: To clarify, I want to force an update to stories with Epic Links via Automation, but when I do things like add a Label or add a Comment to the story via Automation, that does not kick off the Automation pictured above. I don't understand why! If I make the same change manually to the story with the Epic Link, the Automation above kicks off.


author: Marc - Devoteam
body: Hi [@Kathy Dickason](/t5/user/viewprofilepage/user-id/3909439)

Check the option:

"Check to allow other rule actions to trigger this rule. Only enable this if you need this rule to execute in response to another rule"

This option can be found in the rule details.


author: Kathy Dickason
body: THANK YOU!!!!!!! I can't believe how much time I wasted. You're wonderful!!!!


author: Kathy Dickason
body: [@Marc - Devoteam](/t5/user/viewprofilepage/user-id/3796976) I'm hoping you can help me. My automation using   
{{#=}}{{issue.Total Resolved Points}} / {{issue.Total Points}} \* 100{{/}} works in some cases, then does not. I'm getting this in the Audit log when it does not (see screen cap). Any ideas? What is strange is that it sometimes works (see second screen cap). ![Screenshot 2024-08-30 140509.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/344853i620F253190657491/image-size/large?v=v2&px=999 "Screenshot 2024-08-30 140509.jpg")![Screenshot 2024-08-30 140728.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/344854i924DEFF6882EF5EA/image-size/large?v=v2&px=999 "Screenshot 2024-08-30 140728.jpg")


author: Marc - Devoteam
body: Hi [@Kathy Dickason](/t5/user/viewprofilepage/user-id/3909439)

This will occur when you have the incorrect smart value for the field, as it becomes an empty/null value in the expression.

So if the field has no value, this can occur.

You could set your calculation like this:  

{{#=}}{{issue.Total Resolved Points\|1}} / {{issue.Total Points\|1}} \* 100{{/}}  

The the field always has 1 as default in the calculation, if the field is empty in an issue. When performing the automation.


author: Kathy Dickason
body: You are correct again! My Automation to calculate the Total Resolved Points was entered in a way that after the result was calculated I set the automation to clear the field mistakenly! I just had to fix that and it all appears to be working now. You're so wonderful!!


author: Trudy Claspill
body: Hello [@Kathy Dickason](/t5/user/viewprofilepage/user-id/3909439)

In your post tags you have indicated both Data Center and Server. Which are you actually using, and what version?

Are you going to want to use that Percent Complete field within Filters?

As alluded to by the reference [@Nicolas Grossi](/t5/user/viewprofilepage/user-id/676185) provided, Automation for Jira could be used to accomplish this. However, the functionality available differs based on the product you are using and the version of the product. Here is the home page for the latest documentation of the Automation feature in Jira Data Center.

<https://confluence.atlassian.com/automation/>

Jira Server/Data Center does not natively offer scripted or calculated fields, so Automation is a native method for accomplishing your requirement. You can also use the field in Filters if you populate it with this method.

Not all users can create Automation Rules. You may need to get help from your Project Administrator or Jira Administrators to get the rule created.

You said you have ScriptRunner. You could alternately use a [Script Field](https://docs.adaptavist.com/sr4js/latest/features/script-fields) for Percent Complete.

comments: author: Kathy Dickason
body: Data Center.


author: Kathy Dickason
body: I would need to know what to type in the Script Field... Unfortunately, I'm not a software engineer.


author: Nicolas Grossi
body: [@Kathy Dickason](/t5/user/viewprofilepage/user-id/3909439) you might review the following thread:<https://community.atlassian.com/t5/Jira-questions/Calculate-sum-of-values-of-2-custom-fields-in-other-custom-field/qaq-p/726417>

Nicolas


Tags: data-center

jira-data-center

jira-server

server