Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,759
Community Members
 
Community Events
184
Community Groups

Multiply 2 numerical custom fields and display result in third custom field

Looking for a script that can be used to display the numerical outcome of two numerical custom fields in scriptrunner. Preferably behavuiour, but am open to adding in listener, custom scriptrunner field, or post function. Will need specifics as I'm very new to scriptrunner.

Custom Field A*Custom Field B=Custom Field C

3 answers

1 accepted

1 vote
Answer accepted

Thank you all. I found a solution via creating a custom field in scriptrunner. Below is what I used

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def CustomFieldA = customFieldManager.getCustomFieldObjectsByName("CFA")[0]
def CustomFieldB = customFieldManager.getCustomFieldObjectsByName("CFB")[0]

def CustomFieldAValue = (issue.getCustomFieldValue(CustomFieldA) ?: 0) as float
def CustomFieldBValue = (issue.getCustomFieldValue(CustomFieldB) ?: 0) as float

return (CustomFieldAValue * CustomFieldBValue)
2 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 13, 2023

Hi @Adrian_Avalos and welcome,

you could use a calculated custom field provided by Script Runner and use the following code :

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def aCF = customFieldManager.getCustomFieldObjectByName("Custom Field Name A")

def bCF = customFieldManager.getCustomFieldObjectByName("Custom Field Name B")

def aS = issue.getCustomFieldValue(aCF) as String

def bS = issue.getCustomFieldValue(bCF ) as String

def a = aS as Double

def b = bS as Double

if (a == null || b == null) return null

return (a * b) as Double

Please try it and let me know if it works.

Fabio

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 13, 2023

I would use a version of Scriptrunner with HAPI enabled:

def issueKey = "YOUR_ISSUE_KEY"
def firstNumberField = "First Number Field"
def secondNumberField = "Second Number Field"
def resultField = "Result Field"

def issue = Issues.getByKey(issueKey)

def firstNumber = issue.getCustomFieldValue(firstNumberField) as Double
def secondNumber = issue.getCustomFieldValue(secondNumberField) as Double
def result = firstNumber * secondNumber

issue.update {
    setCustomFieldValue(resultField, result)
}

This would work as a console script, but you would remove "issueKey" for a post-function or listener, and if you did it as a scripted field, it gets even shorter, as you drop the "issue update" bit, and instead of "Def result = ", use "return "

I'd avoid a Behaviour for this, because that means having fields on screen that people could then amend later, and won't work if people make updates or edits with REST calls or apps that don't use the API.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events