Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Count times an issue uses a transition

Sharon Connell
Contributor
February 27, 2018

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()

2 answers

0 votes
siva
Contributor
January 19, 2022

@Sharon Connell 

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.

https://community.atlassian.com/t5/Jira-Service-Management/Wanted-script-for-Scriptrunner-Transition-count-in-workflow/qaq-p/1916606#M96273

Thanks,

Siva.

0 votes
Sharon Connell
Contributor
February 27, 2018

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()

Suggest an answer

Log in or Sign up to answer