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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Counting issues going through a status during a day

Hi,

For a specific status within the workflow I need to count how many issues were previously moved to this status within the project on a single day. There is a custom field in which I would like to store this value for each item moved to the status that day. e.g. 2 issues are moved to Status X today, then the values shall be 1 and 2 respectively

My first idea is to add a post-function to the transition leading to that status. However, this is beyond my groovy programming capabilities. Anyone can help to write a fast and smooth script to do this? (I am using Jira 7.2 and ScriptRunner 5) Thanks in advance!

1 answer

Hi All,

I was able to write the following script. This works well, however it is very slow e.g. with having 100 issues in bulk edit.

Can anyone help improving and making faster by removing the nested iterations?

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def dnr = customFieldManager.getCustomFieldObject("customfield_10809")
if (issue.getCustomFieldValue(dnr) == null)
{
def cal = Calendar.instance
def diff = Calendar.SUNDAY - cal.get(Calendar.DAY_OF_WEEK)
cal.add(Calendar.DAY_OF_WEEK, diff)
Date dd = cal.getTime()

def issueMgr = ComponentAccessor.getIssueManager()
long projectid = 10300
def issues = issueMgr.getIssueObjects(issueMgr.getIssueIdsForProject(projectid))

int transitions = 0

for(item in issues)
{
def changeHistories = ComponentAccessor.changeHistoryManager.getChangeHistoriesSince(item, dd)

for(changeHistory in changeHistories) {
for(changeItem in changeHistory.changeItems) {
if("status".equals(changeItem.field)) {
if("Package".equals(changeItem.newstring))
{
transitions += 1
}
}
}
}

}

issue.setCustomFieldValue(dnr,(transitions+1).toString())
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,193 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you