How to generate a calculation of total time spent grouped by field type multiple user picker?

PMO Team November 8, 2018

This is the sample of what I want to generate which is the "Expected Total Timespent by User" column. 

Timespent.PNG

 

I have wrote a code and it was no error but it does not generate the expected result like above. For info the Ops Lead / PM is multiple user picker field type. Can someone help me on this? 

Here is the code:-

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.bc.issue.search.SearchService.ParseResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue


def lead = getCustomFieldValue("OPS Lead/PM ")

def jqlSearch = /worklogDate >= startOfMonth(-1) and worklogDate <= endOfMonth(-1) AND project = "Dev Enhancement Operation" AND type not in ("Deployment Request", Design, Improvement, "Miscellaneous Request", "New Feature", "Release Note", Test, “Customer Survey”, ITC, “TBET Epic”, Tracking, “WAF Testing” ) AND "OPS Lead\/PM" = "${lead}"/

JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class)
def ParseResult parseResult = searchService.parseQuery(authenticationContext.getLoggedInUser(), jqlSearch)

def teamTotalTimeSpent = 0
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def totalTeamTimeSpent = customFieldManager.getCustomFieldObjectByName("TotalTimeSpent")

if(lead){
if (parseResult.isValid()) {
try {
def SearchResults results = searchService.search(authenticationContext.getLoggedInUser(), parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = results.getIssues()
issues.each {
if (it.getCustomFieldValue(totalTeamTimeSpent))
teamTotalTimeSpent += (double) it.getCustomFieldValue(totalTeamTimeSpent)
}
} catch (SearchException e) {
e.printStackTrace()
}
} else {
log.warn("Invalid query")
return null
}

return teamTotalTimeSpent
}
else return null

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events