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
Thank you all. I found a solution via creating a custom field in scriptrunner. Below is what I used
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 { setCustomFieldVa
lue(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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.