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()
I'm also looking for similar script can you please help with the script here is my question link below and your help much appreciated.
Thanks,
Siva.
So I answered this myself by making '0' the default value. <sigh>
// 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
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.