How do i set a custom field with total logged time in a project?

I'm looking to create a new jira issue type to enable me to have an issue that holds project health information. In this, I would like a number of custom fields that pull infomation in from across all issues in the project.

I want to create a custom field (e.g. SIL script) for each of the following from all issues in the project:

sum of logged time
sum of original estimate
sum of time remaining

 

This can be used to estimate %progress for instance

Does anyone know of a SIL or perhaps a Scriptrunner script can do this?

Thanks

 

2 answers

1 accepted

0 vote

I recently wrote a very similar script for a client, so here's a freebie for ya! Instead of adding a comment at the end of the script, you'd just have to make a few mods to set values in your specific custom fields.

The trick is figuring out when to invoke this script. I used SIL Listeners w/ Power Scripts to run this script when an issue is created, issue is updated, or work is logged on an issue. You might consider Live Fields on relevant screens as an alternative.

/* This script will run whenever an issue is created, updated, or work is 
logged on an issues in the applicable project.
*/

string projectInScope="PRDT"; // the project you want to sum up
string masterIssue="PRDT-45"; // issue where you want to capture this info

if(project==projectInScope) { // if invoked via listener, limit the scope
string jql="project="+projectInScope;
string [] allProjectIssues=selectIssues(jql);
string issue;
string commentText;

interval sumOriginalEstimate;
interval sumTimeSpent;
interval sumTimeRemaining;

number hoursOriginalEstimate;
number hoursTimeSpent;
number completePercent;

number countIssues=0;

for(issue in allProjectIssues) {
sumOriginalEstimate += %issue%.originalEstimate;
sumTimeSpent += %issue%.timeSpent;
countIssues +=1;
}

sumTimeRemaining = sumOriginalEstimate - sumTimeSpent;
hoursTimeSpent = sumTimeSpent;
hoursOriginalEstimate = sumOriginalEstimate;
completePercent = round((hoursTimeSpent/hoursOriginalEstimate)*100,0);

string commentTextA = "This project has *"+sumOriginalEstimate+"* estimated work";
string commentTextB = " with *"+sumTimeSpent+"* spent for a total of *";
string commentTextC = ""+sumTimeRemaining+"* hours remaining. ";
string commentTextD = "It is *"+completePercent+"%* complete.";
commentText = commentTextA + commentTextB + commentTextC + commentTextD;
addComment(masterIssue, currentUser(), commentText);
}

Thank you very much

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

255 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you