Document toolboxDocument toolbox

(8.8.X) Expired project

Description

Returns if the project is expired based on the remaining time or in the expiration date

Configuration

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

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

3. Create a Projectrak Date field called "Expiration Date".

4. Create a Projectrak Script field called "Expired project".

5. Insert the following Groovy script and modify according to your instance into "Expired Project" field:

PACK_SIZE_FIELD_ID: Line 12 in the script. In the example we are using 122. Please use the ID that corresponds to your Duration field

TOTAL_TIME_SPENT_FIELD_ID: Line 13 in the script. In the example we are using 82. Please use the ID that corresponds to your Cumulative field with total Time Spent

EXPIRATION_DATE_FIELD_ID: Line 14 in the script. In the example we are using 12. Please use the ID that corresponds to your Date field with the due of the project


Groovy Script

expired-project.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.date.DateField
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
def EXPIRATION_DATE_FIELD_ID = 121

// Components
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)

// Get the fields
def packSizeField = fieldService.get(PACK_SIZE_FIELD_ID)
def totalTimeSpentField = fieldService.get(TOTAL_TIME_SPENT_FIELD_ID)
def expirationDateField = fieldService.get(EXPIRATION_DATE_FIELD_ID)

// Get the field values in the current project
def packSize = valueService.getValue(project, (DurationField) packSizeField) ?: 0
def totalTimeSpent = valueService.getValue(project, (CumulativeField) totalTimeSpentField) ?: 0
def expirationDate = valueService.getValue(project, (DateField) expirationDateField)

// Conditions
def timeConsumed = packSize <= totalTimeSpent
def expiredDate = expirationDate ? expirationDate <= (new Date()).previous() : false
def isExpired = timeConsumed || expiredDate

// Returns true any of the conditions is passed

return isExpired?"TRUE":"FALSE"


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

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

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