Forums

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

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

Al
Contributor
September 6, 2017

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

1 vote
Answer accepted
Justin Evans
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.
September 7, 2017

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);
}
0 votes
Al
Contributor
September 10, 2017

Thank you very much

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events