(8.12.X 2) Calculation: remaining budget
Description
It returns the calculation of the Budget minus the Incurred Cost in the current project
Configuration
1. Create a Projectrak Number field called "Budget".
2. Create a Projectrak Script field called "Incurred Cost"
3. Create a Projectrak Script field called "Remaining budget.
4. Insert the following Groovy script and modify according to your instance into "Remaining budget" field
Groovy Script
remaining-budget.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.number.NumberField import com.deiser.jira.profields.api.field.script.ScriptField import com.deiser.jira.profields.api.value.ValueService import java.text.NumberFormat // Configuration def BUDGET_FIELD_ID = 20 def INCURRED_COST_FIELD_ID = 22 // Components def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class) def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class) def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext // Get the fields def budgetField = fieldService.get(BUDGET_FIELD_ID) def incurredCostField = fieldService.get(INCURRED_COST_FIELD_ID) // Get the field values in the current project def budget = valueService.getValue(project, (NumberField) budgetField) ?: 0 def incurredCost = valueService.getValue(project, (ScriptField) incurredCostField)?:"0" def incurredCostBigDecimal = new BigDecimal(incurredCost) // Returns the difference between the budget and the incurred cost def numberFormat = NumberFormat.getInstance(jiraAuthenticationContext.locale) numberFormat.maximumFractionDigits = 0 numberFormat.minimumFractionDigits = 0 numberFormat.groupingUsed = false return numberFormat.format((budget - incurredCostBigDecimal)<0?0:(budget - incurredCostBigDecimal))
5. Configure the project's layout including all of the fields created.
6. Associate the Layout to the project you need this information to be applied to.
7. The result show 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).