Document toolboxDocument toolbox

To learn more about Tempo products, please visit our Help Center. For support, see our Support Portal.

Filtering by a worklog attribute

The script will search/return all worklogs on an issue with a certain worklog attribute.

import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.tempoplugin.core.datetime.api.TempoDate import com.tempoplugin.worklog.v4.rest.InputWorklogsFactory import com.tempoplugin.worklog.v4.rest.TimesheetWorklogBean import com.tempoplugin.worklog.v4.services.WorklogService import org.apache.log4j.Level import org.apache.log4j.Logger import com.tempoplugin.core.workattribute.api.WorkAttributeService import com.tempoplugin.core.workattribute.api.WorkAttributeValueService import com.atlassian.jira.issue.worklog.Worklog import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue def myLog = Logger.getLogger("com.onresolve.jira.groovy") myLog.setLevel(Level.DEBUG) @WithPlugin("is.origo.jira.tempo-plugin") @PluginModule WorkAttributeService workAttributeService @PluginModule WorkAttributeValueService workAttributeValueService def worklogManager = ComponentAccessor.worklogManager def IssueManager = ComponentAccessor.getIssueManager() MutableIssue issue = IssueManager.getIssueObject("WIKK-20") def worklogs = worklogManager.getByIssue(issue) // Filter the worklogs which are marked as "Remote" def remoteLogs = worklogs.findAll { worklog -> def attribute = workAttributeService.getWorkAttributeByKey("_WorklogCategory_").returnedValue def attributeValue = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue if (attributeValue) { //myLog.info("Worklog attribute value: " + attributeValue.value) if(attributeValue.value=="Development") { //myLog.info("Worklog attribute value: " + attributeValue.value) attributeValue } } } // Sum the remote time in seconds. If there aren't any remote worklogs, just return null remoteLogs.sum { Worklog worklog ->worklog.timeSpent} as Long