Field to calculate sum of two different fields

Anil 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 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Robert Wen_ReleaseTEAM_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 September 24, 2021

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

Robert Wen_ReleaseTEAM_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 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_ReleaseTEAM_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 24, 2021

And you created the new field in Scriptrunner?

Anil 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_ReleaseTEAM_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 September 24, 2021

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

Robert Wen_ReleaseTEAM_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 24, 2021
TAGS
AUG Leaders

Atlassian Community Events