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?



2 answers

1 accepted

1 vote
Accepted answer

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
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,686 views 3 11
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