Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Script Runner to perform Estimate at Complete

This is my first Script Runner Script.  have been using online examples and tutorials but I am still stuck. I would like the script to add all the logged hours in the subtasks and add all the remaining hours and figure out the estimate at complete (EAC) which is a standard Project Management measurement.  I have over simplified the code with the hopes that I could find the problem but still no luck. I ned help. Thanks in Advance for your help.
1) I recieve no errors but I believe the code is not passing this If statement.... Why does the getIssueType not match the "Sub-task" when there are plenty of subtasks for this issue. 
 
if(mySubTask.getIssueType() == "Sub-task"){
2) I cannot figure out the steps to setup a logger. I think I need to setup a JIRA listener for the loogger? But I am not confident and almost every tutorial starts with a logger already setup?
Here is the script so far
________________________________________________________
package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.worklog.WorklogManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
import org.apache.log4j.Logger
import org.apache.log4j.Level

 

//def log = Logger.getLogger("something?????")
//log.setLevel(Level.DEBUG)

 

//define the worklog manager
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
def workLogs = worklogManager.getByIssue(issue)

 

//define variables
def estimateAtCompleteSeconds = 0
def estimateAtCompleteHours = 0
def calculateTimeSpent = 0
def calculateRemainingTime = 0



SubTaskManager mySubTaskManager = ComponentAccessor.getSubTaskManager();
Collection<Issue> mySubTasks = issue.getSubTaskObjects()

 

def x = 0
def y = 0

 

if (mySubTaskManager.subTasksEnabled && !mySubTasks.empty) {



    mySubTasks.each { mySubTask->

 

        if(mySubTask.getIssueType() == "Sub-task"){
        x = mySubTask.getTimeSpent()?: 0
        y = mySubTask.getOriginalEstimate()?: 0
        calculateTimeSpent = calculateTimeSpent = x
        calculateRemainingTime = calculateRemainingTime + y
        }
    }

 

}



//log the info for debugging
//log.debug(calculateTimeSpent)
//log.debug(calculateRemainingTime)

 

estimateAtCompleteSeconds = calculateTimeSpent + calculateRemainingTime

 

//log the info for debugging
//log.debug(estimateAtCompleteSeconds)

 

// function to convert the seconds to hours
if(estimateAtCompleteSeconds){
estimateAtCompleteHours = estimateAtCompleteSeconds / 3600
}

 

//log the info for debugging
//log.debug(estimateAtCompleteHours)

 

return estimateAtCompleteHours



1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 10, 2023

Welcome to the Atlassian Community!

I'd take a step back from this.  Jira already has issue fields that sum up all the parts of the time-tracking field - you don't need to duplicate this!

Thanks very much, Which system field provides the EAC so I can add it to the parent tickets and put it on a two dimensional filter gadget. It's the biggest complaint our Project Managers have.

We then also need a Variance field which calculates the EAC - OriginalEstimate. So that is the next step for scriptRunner and I have never found this field either.

We would like gadgets on dashboards to show this information. Currently we need to export to excel and manually apply the calculations which is manual labor once a week and time consuming.

Thanks for your help!

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 10, 2023

It's the time-tracking field, which I sometimes call a compound field, because it contains a load of others.

  • Σ Original Estimate
  • Σ Progress
  • Σ Remaining Estimate
  • Σ Time Spent

But you won't be able to use it in the two-dimensional filter gadget, they only work with list fields.

You can get them in excel exports though, that could save you a lot of time.

Yes I have used all of these fields. But these fields are not EAC or Variance so the Project Managers have asked for more.

Ideally they want 

EAC = Σ Remaining Estimate + Σ Time Spent

Would you know how to create a scripted field with the above total sum? This is ultimately what I was trying to do. Also this?

Variance = Σ Original Estimate - (Σ Remaining Estimate + Σ Time Spent)

To get these important Project Management numbers we have to export into excel and do the caluclations with some manual work.

Thanks very much!

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 10, 2023

I think you have a bit of a problem here.

The time tracking fields are nothing to do with "Estimate at complete".  They are telling you how much time was estimated initially, and how much your people actually did.

"Estimate at complete" should be a measure of what a team said they could do.  Something they can then compare against what they delivered.

Your estimate compared with your delivery is a very important metric, and if you are doing it as a time estimate, that's the right way to look at it.

But when you are using an Agile tool, the question is not "EAC = Σ Remaining Estimate + Σ Time Spent", the question is "why did we not deliver what we said we would?".

So, I have a question that is a bit blunt - What is your actual process?  Are you trying to do Scrum, Kanban, Lean (and its subsets) or something else?   I ask because it feels like you may be trying to wedge the idea of sprints into a linear non-agile process.

Thanks for asking! We do not do Agile. We use V-MODEL following a heavy ISO Software Engineering process and International standards process.  We are able to use JIRA for everything we need other then the few measurenements needed by the Project Managers following a PMP training process. Script Runner was recently bought with the expectation that we could script the solution that does not come out of the box.

I would like to find a way to create a scripted field that can add up all the remaining work and work logged and produce a Estmate At Complete. From the PMBOK Guide the sum of the actual cost to date and the estimate to complete.

I wonder if maybe you can anwer the 2nd question about logging? Because I still don't know how to do the logging.

Like Nic Brough -Adaptavist- likes this
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 12, 2023

Thank you for taking the time to explain that in detail. 

I think I now understand where your need for an EAC comes from, and yes, the sigma-fields don't meet that need (they'll give you the right answer during part of the lifecycle, but not all of it) 

I think you're absolutely spot-on to blame the "if" in your code, the line

if(mySubTask.getIssueType() == "Sub-task")

is not going to give you a "true".  I'm pretty sure getIssueType() returns an issue type object, not a string, so it will never contain "Sub-task", whatever the name of the sub-task type.

A simple fix would be

 if ("Sub-task" == mySubTask.getIssueType().getName() )

but that locks you into having a fixed sub-task name, and your code will fail if someone renames sub-task, and it won't run for other sub-task types.

So, assuming you really do want to include all the sub-tasks of different types, I would use

if (mySubTask.getIssueType().isSubTask() )


For clever logging in scripts, have a skim of https://docs.adaptavist.com/sr4js/latest/best-practices/logging/advanced-logging to see what might work best for you!

Thank you very much! Yes this is the solution and we have a fixed sub-task name it will never change for an EAC. This is great thank you very much. I have it working now and the dashboard is working great now!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events