Document toolboxDocument toolbox

(8.16.X) Calculation: remaining time

Description

It returns the difference between the Pack Size and the Total Time Spent in the current project

Configuration

1. Create a Projectrak Duration field called "Pack Size".

2. Create a Projectrak Cumulative field called "Total Time Spent".

3. Insert the following Groovy script and modify according to your instance into "Remaining time" field

COST_FIELD_ID: Line 12 in the script. In the example we are using 21. Please use the ID that corresponds to your "Cost Size" field

Groovy Script

remaining-time.groovy
package deiser.profields.scripts import com.atlassian.jira.component.ComponentAccessor import com.deiser.jira.profields.api.field.FieldService import com.deiser.jira.profields.api.field.cumulative.CumulativeField import com.deiser.jira.profields.api.field.duration.DurationField import com.deiser.jira.profields.api.value.ValueService // Configuration def PACK_SIZE_FIELD_ID = 122 def TOTAL_TIME_SPENT_FIELD_ID = 82 // Components def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class) def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class) def jiraDurationUtils = ComponentAccessor.jiraDurationUtils // Get the fields def supportPackSizeField = fieldService.get(PACK_SIZE_FIELD_ID) def totalTimeSpentField = fieldService.get(TOTAL_TIME_SPENT_FIELD_ID) // Get the field values in the current project def supportPackSize = valueService.getValue(project, (DurationField) supportPackSizeField) ?: 0 def totalTimeSpent = valueService.getValue(project, (CumulativeField) totalTimeSpentField) ?: 0 // Returns the difference between the budget and the incurred cost return jiraDurationUtils.getShortFormattedDuration(supportPackSize < totalTimeSpent ? 0L : (supportPackSize - totalTimeSpent).longValue())

4. Configure the project's layout including all of the fields created.

5. Associate the Layout to the project you need this information to be applied to. 

6. 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).