Counting issues going through a status during a day

Sandor Mathe February 21, 2021

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

0 votes
Sandor Mathe February 23, 2021

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