To help with bug prioritization, would like to automatically calculate a Score with ScriptRunner
There are 4 fields.
- Type - 1,2,3,4,5 (select list, single choice)
- Priority - 1,2,3,4,5 (select list, single choice)
- Impact - 1,2,3,4,5 (select list, single choice)
- Score - Number Field
When all three fields (Type, Priority and Impact) are selected, would like to automatically calculate the score based on a calculation.
Here is what I have, not sure where I am struggling.
// Get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def input1Field = customFields.find { it.name == 'Type' }?.id
def input2Field = customFields.find { it.name == 'Priority' }?.id
def input3Field = customFields.find { it.name == 'Impact' }?.id
def outputField = customFields.find { it.name == 'Score' }?.id
def input1 = issue.fields[input1Field] as Integer
def input2 = issue.fields[input2Field] as Integer
def input3 = issue.fields[input3Field] as Integer
def output = (input1*input2*input3*100)/125
if (output == (issue.fields[outputField] as Integer)) {
logger.info("already been updated")
return
}
put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
(outputField): output
]
])
.asString()