Document toolboxDocument toolbox

(8.11.X) OverRun

Description

Overrun% = [Time Spent + Remaining Estimate - Original Estimate] / Original Estimate

Configuration

1. Create a Projectrak Script field called "OverRun"

2. Insert the following Groovy script and modify accordingly to your instance:

Groovy Script

overrun.groovy
package deiser.profields.scripts

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.project.Project
import com.atlassian.jira.web.bean.PagerFilter

def PROJECT_ID = project.id

def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService)
def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext

def loggedInUser = jiraAuthenticationContext.getLoggedInUser()
def query = JqlQueryBuilder.newBuilder().where().project(PROJECT_ID).buildQuery()

def sumTimeSpent = 0L
def sumRemainingEstimate = 0L
def sumOriginalEstimate = 0L
searchService.search(loggedInUser, query, PagerFilter.unlimitedFilter).results
        .each { issue ->
            sumTimeSpent += issue.getTimeSpent() == null ? 0 : issue.getTimeSpent()
            sumOriginalEstimate += issue.getOriginalEstimate() == null ? 0 : issue.getOriginalEstimate()
            sumRemainingEstimate += issue.getEstimate() == null ? 0 : issue.getEstimate()
        }

if(sumOriginalEstimate == 0L) return "Original Estimate does not have value"

def overRun = (sumTimeSpent + sumRemainingEstimate - sumOriginalEstimate) / sumOriginalEstimate
return String.format("%.1f", overRun) + "%" 

3. Configure the project's layout including "OverRun

4. Associate the layout to the project you need this information to be applied to. 

5. The result should be something like this: (please, keep in mind that this is only an example and your results should vary from what it is shown in the screenshot).