I am trying to user ScriptRunner to count how many times an issue uses a particular transition (QA Rejected). I got it to work if there was already a value in the custom field (Counter) but I can't seem to make it work if the custom field has a null value. I am not a developer and this is as far as I could get. Any help is much appreciated!
// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def inputCfId = customFields.find { it.name == 'Counter' }?.id
def input1 = issue.fields[inputCfId] as Integer
if (input1 == Integer) {
input1 = 0
return
}
def output = input1 + 1
put("/rest/api/2/issue/${issue.key}")
// .queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields:[
(inputCfId): output
]
])
.asString()