I've seen a bunch of other similar questions being asked but none of the provided code seems to work so I've had to cobble together this:
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager
def CA = ComponentAccessor.getCustomFieldManager()
def fSev = issue.getCustomFieldValue(CA.getCustomFieldObject('customfield_10912'))
def iSev
if (fSev) {
iSev = ((LazyLoadedOption)fSev).getValue().toInteger()
} else { 1 }
def fImp = issue.getCustomFieldValue(CA.getCustomFieldObject('customfield_10914'))
def iImp
if (fImp) {
iImp = ((LazyLoadedOption)fImp).getValue().toInteger()
} else { 1 }
def num = ( iSev + iImp ) / 4
String pValue;
switch (num) {
case 1: pValue = "Lowest"; break;
case 2: pValue = "Low"; break;
case 3: pValue = "Medium"; break;
case 4: pValue = "High"; break;
case 5: pValue = "Highest"; break;
default: pValue = "Lowest"
}
def pfield = ComponentAccessor.getComponent(PriorityManager).priorities
def pID = pfield.findByName(pValue)
if (issue.issueType.name == 'Bug' ) {
issue.setPriorityId(pID.id)
}
There are 2 integers (iSev and iImp, both a value between 1 and 10), that this pulls from and 5 Priority levels (pValue).
This code doesn't produce any errors, but it also doesn't set the priority value at all, what am I missing?
Hi @Dan Earle,
I used ConstantsManager to get priority which worked for me. this may give you some idea
import com.atlassian.jira.component.ComponentAccessor
def constantsManager = ComponentAccessor.getConstantsManager()
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Field")
def fValue = issue.getCustomFieldValue(field) as Integer
if(fValue == 1){
issue.setPriorityId(constantsManager.getPriorityObjects().findByName("P1").id)
}else{
issue.setPriorityId(constantsManager.getPriorityObjects().findByName("P3").id)
}
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.