count the stories/tasks under an Epic

CC
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.
May 25, 2023

We need to make a dashboard displaying below two values

Epic Name            No of stories/tasks created under Epic   

Please help us to count the stories/tasks.  We have scriptrunner for Jira Cloud.  I'm a neophyte with Scriptrunner.  I read that a scripted field might be a good answer.  This was recommended on another question however it's not working for me. 

  • The first warning says "Unable to resolve class com.atlassian.jira.issue.issue"
  • The second warning says "Unable to resolve class issue @ line 8, column 15"

Please help!Capture.JPG

4 answers

1 accepted

1 vote
Answer accepted
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.
May 26, 2023

Hi @CC 

From the script that you have shared, it appears that you are trying to use the Jira Server / DC API in the Jira Cloud via ScriptRunner.

This will not work. 

If you intend to initialise any object, it must be done via REST requests.

In the editor that you are using, if you click on the sample codes provided, it will show you how to make the REST Requests.

I will try to prepare a sample for this.

Thank you and Kind regards,

Ram

CC
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.
May 31, 2023

@Ram Kumar Aravindakshan _Adaptavist_   Any chance you can prepare a sample?  I'm not that advanced in REST.

Like John Funk likes this
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.
June 13, 2023

Hi @CC

Sorry for the late reply. I've been a bit busy and didn't have time to play around with this.

Below is the sample working Cloud script for your reference:-

def issueKey = 'MOCK-1' //Change the Epic Key according to your environment

def jql = "rest/api/2/search?jql='Epic Link'=${issueKey}"
def filteredJql = jql.replace(" ","%20").replace('"',"%22") def body = get(filteredJql).asObject(Map).body def issuesInEpic = body['issues']['key'] def storyPoints = [] as List<Double> issuesInEpic.findAll { def childIssue = get("/rest/api/2/issue/${it}").header('Content-Type', 'application/json').asObject(Map) def issueType = childIssue.body.fields['issuetype']['name'] if (issueType in ['Story', 'Task']) {

//Change the custom field id according to your Cloud instance
storyPoints << Double.parseDouble(childIssue.body.fields['customfield_10018'] as String) } } storyPoints.sum()

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

If you observe the example above, I need to make a couple of GET requests and filter out the details accordingly.

Also note that in my Cloud instance, the id for the Story Points field is customfield_10018. You will need to modify this according to your instance.

You can run this on the ScriptRunner console to get the result.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram 

Like John Funk likes this
CC
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.
June 13, 2023

cool.  Thank you so much.  I'll give it a go in a few.

Like John Funk likes this
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.
July 3, 2023

Hi @CC ,

Has your question been answered?

If yes, please accept the answer.

Thank you and Kind regards,

Ram

2 votes
Marlene Kegel - codefortynine
Atlassian Partner
May 30, 2023

Hi @CC,

I am Marlene from codefortynine.

Another option would be our app Dynamic Custom Fields for Jira.

With our app you can add a custom field to your issues, which displays the number of child issues under a parent issue (e.g. epic).

Our app is working with Jira expressions, but we offer a template for your use case. Therefore you don't have to be able to write the expression in order to create the field.

After installation you simply

  • Navigate to the Dynamic Custom Fields config page
  • Select the template "Number of child issues"
  • Click save
  • Add the newly created field as any other custom field to your issues

The field can be used in JQL and your statistics as any other Jira number field. 

dynamic-custom-fields-jira_number-of-child-issues2.png

Dynamic Custom Fields config page

dynamic-custom-fields-jira_number-of-child-issues.png

1 vote
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 26, 2023

Hi @CC 

Not sure if this is what you are looking for or not, but I added an Issue Statistics gadget to the dashboard and used the project for the Project or Saved Filter and the Epic Link field for the Statistic Type. Give that a try and see if that is what you want. 

1 vote
Frederik Vantroys
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.
May 25, 2023

Is it possible Issue has to be wit a capital letter I ?

so : 

import com.atlassian.jira.issue.Issue

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events