Forums

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

Field to calculate sum of two different fields

Anil
Contributor
September 21, 2021

Hi All,

 

I’m new to groovy scripting. I tried multiple options to create a calculated field which should divide the two custom field values.

First field is single select with Numeric values.

second field is number field.

new field = first field / second field

Any help would be greatly appreciated.

 

Thanks in Advance

Anil

1 comment

Comment

Log in or Sign up to comment
Robert Wen_Cprime_
Community Champion
September 21, 2021

How are you defining the new field?  Are you using a plugin like Scriptrunner which allows you to define calculated fields?

Anil
Contributor
September 24, 2021

Yes. We are using ScriptRunner. I am new to Groovy Scripting. 

Robert Wen_Cprime_
Community Champion
September 24, 2021

How did you define the new field (the one that is meant to be the quotient of the other two fields)?  Can you give me a screenshot?

Anil
Contributor
September 24, 2021

This is what i was trying:

import com.atlassian.jira.component.ComponentAccessor

cfA = issue.get(customfield_1234)

cfA = issue.get(customfield_1234)

return cfA / cfB

Robert Wen_Cprime_
Community Champion
September 24, 2021

And you created the new field in Scriptrunner?

Anil
Contributor
September 24, 2021

Yes. I have created new field using scriptrunner. 

Somehow I'm able to add two number fields. But not able to make it with select list with numeric values and another number field. 

Robert Wen_Cprime_
Community Champion
September 24, 2021

I think the problem is with the select list.  You have to convert the numeric values to actual numbers before performing the arithmetic operation.

Anil
Contributor
September 24, 2021

That is where i stopped. Do you have any inputs on how to convert?

Robert Wen_Cprime_
Community Champion
September 24, 2021
TAGS
AUG Leaders

Atlassian Community Events