...
This is an example of what the layout might look like where you can follow up contracted hours by month:
Image Modified
Fields
Field | Type | Details |
---|
Contracted hours / month | Duration | Hours contracted for the service per month |
Work logged - [MONTH] | Script | Total hours logged in a specific month Create 12 fields and replace the variable MONTH to specify every month Create 12 fields and replace the variable YEAR to specify the year Code Block |
---|
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.project.Project
import com.atlassian.jira.web.bean.PagerFilter
// CONFIGURATION -------------------------
def MONTH = 1
def YEAR = 2021
// ---------------------------------------
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService)
def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext
def worklogManager = ComponentAccessor.worklogManager
def jiraDurationUtils = ComponentAccessor.jiraDurationUtils
def loggedInUser = jiraAuthenticationContext.getLoggedInUser()
def query = JqlQueryBuilder.newBuilder().where().project(((Project) project).id).buildQuery()
def worklog = searchService.search(loggedInUser, query, PagerFilter.unlimitedFilter).results
.collect { issue ->
worklogManager.getByIssue(issue)
.findAll { worklog -> worklog != null }
.findAll { worklog -> worklog.startDate[Calendar.YEAR] == YEAR }
.findAll { worklog -> worklog.startDate[Calendar.MONTH] + 1 == MONTH }
.collect { worklog -> worklog.timeSpent }
.sum()
}
.findAll { time -> time != null }
.sum()
jiraDurationUtils.getShortFormattedDuration(!worklog ? 0 : worklog as Long)
|
|
Remaining - [MONTH] | Script | Calculates Contracted hours / Work logged - [MONTH] Replace ESTIMATION_FIELD_ID with the ID of "Contracted hours / month" field Replace WORKLOG_FIELD_ID with the ID of every "Work logged - [MONTH]" field Code Block |
---|
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.duration.DurationField
import com.deiser.jira.profields.api.field.script.ScriptField
import com.deiser.jira.profields.api.value.ValueService
// CONFIGURATION -------------------------
def ESTIMATION_FIELD_ID = 168
def WORKLOG_FIELD_ID = 164
// ---------------------------------------
def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext
def jiraDurationUtils = ComponentAccessor.jiraDurationUtils
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService)
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService)
def worklogString = valueService.getValue((Project) project, (ScriptField) fieldService.get(WORKLOG_FIELD_ID))
def estimated = valueService.getValue((Project) project, (DurationField) fieldService.get(ESTIMATION_FIELD_ID))
def worklog = jiraDurationUtils.parseDuration(worklogString, jiraAuthenticationContext.locale)
def difference = (!estimated ? 0L : estimated as Long) - (!worklog ? 0L : worklog as Long)
return jiraDurationUtils.getShortFormattedDuration(difference < 0 ? 0 : difference)
|
|