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

Accepted Answer
0 votes

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
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

1,354 views 4 6
Join discussion

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