I'm using Scriptrunner to populate a calculated field. If for some reason I need to clear any one of the fields used to make the calculation, I need the calculated field to become null. I'm using this code to calculate the field:
def input1CfId = 'customfield_12326'
def input2CfId = 'customfield_12328'
def input3CfId = 'customfield_12329'
def outputCfId = 'customfield_12330'
def projectKey = "CT"
if (issue == null || issue.fields.project.key != projectKey) {
logger.info("Wrong Project ${issue.fields.project.key}")
return
}
def input1 = issue.fields[input1CfId] as Integer
def input2 = issue.fields[input2CfId] as Integer
def input3 = issue.fields[input3CfId] as java.lang.Float
if (input1 == null || input2 == null || input3 == null) {
logger.info("Calculation using ${input1}, ${input2}, and ${input3} was not possible")
return
}
def output = input1 * input2 / input3
if (output == (issue.fields[outputCfId] as Integer)) {
logger.info("already been updated")
return
}
put("/rest/api/2/issue/${issue.key}")
//.queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()
I tried adding this in line 21 but it didn't work:
if (input1 == null || input2 == null || input3 == null) {
def output = '0'
} Any thoughts about what I could be doing differently here are appreciated!