Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script runner, Script fields, Count Status cycles

Mark Bednarski March 27, 2014

Hi,

I need to display how often an issue has seen a a specific status. For example "How often hade the current issue been on the 'in Progress' status."

Alternatively, the count of a specific transition would give me the same result.

Unfortunately I have no idea how to do this. Can someone help me please?

Thank you
Mark

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2014

You have to search through the change items

changeItems = ComponentAccessor.changeHistoryManager.getAllChangeItems(issue)

of the issue to count the changes to the status.

changeItems?.findAll{it.field == 'status' && it.getTos().values().contains('In Progress')}.size()

Mark Bednarski April 7, 2014

Hi Henning,

I added a Script Runner / script field:

changeItems = ComponentAccessor.changeHistoryManager.getAllChangeItems(issue)
return changeItems?.findAll{it.field == 'status' && it.getTos().values().contains('In Progress')}.size()

But it seems not to work for me. Tried many variations but seems like I can't get it to work :-(

However, thanks Henning for the intial help :-)

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2014

You need the imports and stuff:

import com.atlassian.jira.component.ComponentAccessor

def changeItems = ComponentAccessor.changeHistoryManager.getAllChangeItems(issue)
return changeItems?.findAll{it.field == 'status' && it.getTos().values().contains('In Progress')}.size()

Mark Bednarski April 7, 2014

Actually I tried this:

import com.atlassian.jira.component.ComponentAccessor
def changeItems = ComponentAccessor.changeHistoryManager.getAllChangeItems(issue)
return changeItems?.findAll{it.field == 'status' && it.getTos().values().contains('Not fixed')}.size()

I set the template type to Number and nothing happens when I test it with an issue. Do I get somewhere a log about what goes wrong when I preview a script with a sample issue? This might be able to help me debugging it.

Thank you very much
Mark

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 13, 2014

If you use the number template you have to return a Double. Could you try to add a as Double to the last line?

Mark Bednarski April 13, 2014

I tried

import com.atlassian.jira.component.ComponentAccessor
def changeItems = ComponentAccessor.changeHistoryManager.getAllChangeItems(issue)
return changeItems?.findAll{it.field == 'status' && it.getTos().values().contains('Not fixed')}.size() as Double

but no change. Without any kind of logfile its quite hard to find a place to fix something.

Thanks anyway!
Mark

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 14, 2014

You can print some logging info to the catalina.out file using log.error(). So

log.error changeItems

before the return statement should show you if you get what you expect.

TAGS
AUG Leaders

Atlassian Community Events