How to get count of resolved issues for a specific issue type in ScriptRunner field

James Woyciesjes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 7, 2025

I am looking to populate a scripted field with the number of stories resolved vs. the total number of stories so I can show on a Kanban Card (see image).

The code I have works but I am only able to count all resolved issues vs. total issues linked.

I want the calculation to be limited to Stories only.

In the pasted code, I have a commented out block that will count only linked Stories which I know works fine.

What I am missing is the code that will only count the number of resolved Stories so I can feed that value into the variable "y".

Appreciate any guidance!

 

image.png

 

import com.atlassian.jira.component.ComponentAccessor
 
int x = 0
int y = 0
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getAllIssues()
def resolvedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, issue.reporter).getAllIssues()
 
/*
if (linkedIssues.size() > 0){
  for (int i = 0; i < linkedIssues.size(); i++){
// Use the following IF statements to limit the count to certain issue types
    if (linkedIssues[i].getIssueType().getName() == "Story"){
      x = x + 1
    }
    //if (linkedIssues[i].getIssueType().getName() == "Task"){
      x = x + 1
    }
  }
}
*/
 
// Gets count of linked issues regardless of issue type
x = linkedIssues.size()
 
//Counts number of resolved issues
y = resolvedIssues.count{it.resolution != null}  
 
// Formats output
if (x > 0) {
   if (y > 0) {
  return "[" + y + " of " + x + "]"
}}else return null

 

Additional question:

In lines 6 & 7, is it okay to use currentUser and issue.reporter or will this limit the calculation based on access rights?

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 8, 2025

Hi @James Woyciesjes

Please clarify are you trying to populate the completed Story points in an Epic? If yes, is the Story point total only to be updated in the Epic when the child issues transition to Done?

I do have some examples for this but I need your clarification to confirm which approach you are trying to take.

I am looking forward to your feedback and clarification.


Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer