Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to pull value of a field field based on Assignee and Sprint of the issue

Matthew_Schulz August 20, 2019

Hi,

I'm looking for help with creating a custom field that pulls in the value of "Original Estimate" on any issue based on the Assignee and Sprint of that issue.

  • This can't be user-specific as we need this for a large team. 
  • We can already pull the total from any Sub-tasks, just need to move that over to a custom field.

Ex. Johnny has a Capacity issue with a "Total Hours of Work" field that needs to pull in the total hours of all issues assigned to him during Sprint 1.

  • There is 1 Story with 3 Sub-tasks under it, each with 3 hours on the original estimate and another Story with 8 hours on the original estimate.
  • All issues are assigned to Johnny and Sprint 1.

So the "Total Hours of Work" field on the Capacity issues should 17 hours based on the original estimate from all issues combined.

 

Code to pull in the total hours of Sub-tasks and Story:

import com.atlassian.jira.issue.Issue

long totalSum = 0;
boolean noEstimates = true;
def totalSubTasks = issue.getSubTaskObjects().size()

for(Issue subtask: issue.getSubTaskObjects()){
if(subtask.getEstimate() != null){
totalSum += subtask.getEstimate()
noEstimates = false
}
}
if (issue.getEstimate() != null){
totalSum += issue.getEstimate()
noEstimates = false
}

if (noEstimates == true){
return null
}
else {
return totalSum / 60 / 60
}

 

Any help is much appreciated!

Thanks,

Matt

1 answer

0 votes
brbojorque
Community Champion
August 20, 2019

Hi @Matthew_Schulz ,

You can compose a JQL inside ScriptRunner and return the result that you need, you can then loop it to get the total hours of all result of JQL.

https://scriptrunner.adaptavist.com/latest/jira/jql-functions.html

Matthew_Schulz August 21, 2019

Hi @brbojorque ,

Great idea! But I'm pretty new to Jira, is there a way to query for all issues that belong to an issue by Assignee and Sprint dynamically? It wouldn't really work if we have to add each person in by hand.

Thanks,

Matt

brbojorque
Community Champion
August 21, 2019

Hi @Matthew_Schulz , your problem is very interesting, let me get back to you with a full script.

This is a good idea for keeping the defined/easy to keep track hours per sprint.

brbojorque
Community Champion
August 21, 2019

Hi @Matthew_Schulz ,

Come to think of it, you can actually use the Workload Pie Gadget if you are using the server version of JIRA.

 

df9f6bb1-f6f3-4957-a920-2ab5b3550def.png

 

My sample JQL for the filter and you can group it by assignee

project = SP and Sprint =  openSprints()

 

You will see in the gadget what is the estimates or time spent,

Suggest an answer

Log in or Sign up to answer