Hi,
I have JIRA custom field abc=3, bcd=4 and third custom scriptrunner filed value xyz=12 (abc * bcd)
how i can get the xyz value using groovy script, once we have updated the filed values abc, bcd then immediately calculate the field value xyz.
You could use script field. Here is a script for it:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); return issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("abc"))*issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("xyz"))
You'll need to declare a value as float before multiplying. ScriptRunner doesn't do that for you anymore.
You'll also need to make sure the fields are "Numbers" fields. A "Select" list doesn't work 🙁
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def severity = customFieldManager.getCustomFieldObjectsByName("Severity")[0]
def occurance = customFieldManager.getCustomFieldObjectsByName("Occurance")[0]
def detectability = customFieldManager.getCustomFieldObjectsByName("Detectability")[0]
def severityValue = (issue.getCustomFieldValue(severity) ?: 0) as float
def occuranceValue = (issue.getCustomFieldValue(occurance) ?: 0) as float
def detectabilityValue = (issue.getCustomFieldValue(detectability) ?: 0) as float
return (severityValue * occuranceValue * detectabilityValue)
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.