I've got MyGroovy add-on, similar to Scriptrunner, and I've been trying to use it to create a scripted custom field "risk" which calculates the value based on
Impact X Probability - both these fields are single list type custom fields.
The following is the groovy script I've used, which compiles fine, but the field is not appearing on the IssueType:
It is currently associated to screens for Epic, Story and Bugs. Am I missing some step in between? Any help is greatly appreciated!
===================||======================
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import java.lang.Object
import java.lang.Double
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
def impact = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("TE Business Impact").toString()
def probability = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("TE Technical Complexity").toString()
def risk
if ((impact!="null") && (probability!="null")) {
risk = Double.parseDouble(impact) * Double.parseDouble(probability)
} else {
risk = null
}
return risk
This is how we managed to get it working at Collinson:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import java.lang.Double
// needed to get custom fields
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get generic custom fields
def impact = customFieldManager.getCustomFieldObjectsByName("TE Business Impact").first()
def probability = customFieldManager.getCustomFieldObjectsByName("TE Technical Complexity").first()
// get instances for this issue
def impactValue = issue.getCustomFieldValue(impact)
def probabilityValue = issue.getCustomFieldValue(probability)
// get actual selected values
def selectedImpactValue = ((LazyLoadedOption)impactValue).getValue() as Double
def selectedProbabilityValue = ((LazyLoadedOption)probabilityValue).getValue() as Double
// calculate risk
def riskValue = null
if (selectedImpactValue && selectedProbabilityValue) {
riskValue = selectedImpactValue * selectedProbabilityValue
}
return riskValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
You're not getting values this way:
ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("TE Business Impact").toString()
You're only getting the custom field. So your script is likely throwing errors.
Your script should look something like this:
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.CustomFieldManager
@StandardModule
CustomFieldManager customFieldManager
Option impact = (Option) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("TE Business Impact").first())
Option probability = (Option) issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("TE Technical Complexity").first())
if ((impact != null) && (probability != null)) {
//assuming you want to parse names of options as numbers
return Double.parseDouble(impact.value) * Double.parseDouble(probability.value)
}
return null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is how we managed to get it working at Collinson:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import java.lang.Double
// needed to get custom fields
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get generic custom fields
def impact = customFieldManager.getCustomFieldObjectsByName("TE Business Impact").first()
def probability = customFieldManager.getCustomFieldObjectsByName("TE Technical Complexity").first()
// get instances for this issue
def impactValue = issue.getCustomFieldValue(impact)
def probabilityValue = issue.getCustomFieldValue(probability)
// get actual selected values
def selectedImpactValue = ((LazyLoadedOption)impactValue).getValue() as Double
def selectedProbabilityValue = ((LazyLoadedOption)probabilityValue).getValue() as Double
// calculate risk
def riskValue = null
if (selectedImpactValue && selectedProbabilityValue) {
riskValue = selectedImpactValue * selectedProbabilityValue
}
return riskValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is how we managed to get it working at Collinson:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import java.lang.Double
// needed to get custom fields
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get generic custom fields
def impact = customFieldManager.getCustomFieldObjectsByName("TE Business Impact").first()
def probability = customFieldManager.getCustomFieldObjectsByName("TE Technical Complexity").first()
// get instances for this issue
def impactValue = issue.getCustomFieldValue(impact)
def probabilityValue = issue.getCustomFieldValue(probability)
// get actual selected values
def selectedImpactValue = ((LazyLoadedOption)impactValue).getValue() as Double
def selectedProbabilityValue = ((LazyLoadedOption)probabilityValue).getValue() as Double
// calculate risk
def riskValue = null
if (selectedImpactValue && selectedProbabilityValue) {
riskValue = selectedImpactValue * selectedProbabilityValue
}
return riskValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also just to add - I've checked the settings as below, the scripted field name is 'TE RiskScore' and contains the above script:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is how we managed to get it working at Collinson:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import java.lang.Double
// needed to get custom fields
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get generic custom fields
def impact = customFieldManager.getCustomFieldObjectsByName("TE Business Impact").first()
def probability = customFieldManager.getCustomFieldObjectsByName("TE Technical Complexity").first()
// get instances for this issue
def impactValue = issue.getCustomFieldValue(impact)
def probabilityValue = issue.getCustomFieldValue(probability)
// get actual selected values
def selectedImpactValue = ((LazyLoadedOption)impactValue).getValue() as Double
def selectedProbabilityValue = ((LazyLoadedOption)probabilityValue).getValue() as Double
// calculate risk
def riskValue = null
if (selectedImpactValue && selectedProbabilityValue) {
riskValue = selectedImpactValue * selectedProbabilityValue
}
return riskValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.