Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can I calculate custom field values into a custom total field?

Sarah Price March 1, 2023

I'm new to JIRA and I'm trying to add the value of 6 custom fields into a custom Total field.

customfield1 = 10

customfield2 = 10

customfieldTOTAL= 20 - this should be calculated

It looks like you can use smart values to do this but I'm not sure where to put the scripts or how to get it to execute. Any help or documentation would be much appreciated.

I do not have any add-ons right now but am looking to get scriptrunner.

1 answer

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
March 1, 2023

Hi @Sarah Price 

Welcome to the Community!

If you can use the ScriptRunner app, you can easily achieve this.

Define a scripted calculated custom field as below:

 

import com.atlassian.jira.component.ComponentAccessor 

def
customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField1 = customFieldManager.getCustomFieldObjectByName("Custom Field 1")
def customField2 = customFieldManager.getCustomFieldObjectByName("Custom Field 2")
def customField3 = customFieldManager.getCustomFieldObjectByName("Custom Field 3")
def customField4 = customFieldManager.getCustomFieldObjectByName("Custom Field 4")
def customField5 = customFieldManager.getCustomFieldObjectByName("Custom Field 5")
def customField6 = customFieldManager.getCustomFieldObjectByName("Custom Field 6")

def value1 = issue.getCustomFieldValue(customField1) as Double ?: 0
def value2 = issue.getCustomFieldValue(customField2) as Double ?: 0
def value3 = issue.getCustomFieldValue(customField3) as Double ?: 0
def value4 = issue.getCustomFieldValue(customField4) as Double ?: 0
def value5 = issue.getCustomFieldValue(customField5) as Double ?: 0
def value6 = issue.getCustomFieldValue(customField6) as Double ?: 0

return value1 + value2 + value3 + value4 + value5 + value6
Sarah Price March 3, 2023

Thanks. We do not have scriptrunner yet. We are waiting approval and installation. 

Is there an alternate method until then?

Suggest an answer

Log in or Sign up to answer