The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get list of distinct assignees from a filter results using groovy

Lokesh
Contributor
August 12, 2021

We need to get list of distinct assignees from a filter results, using groovy or rest query.

Any ideas much appreciated. Thanks.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Lokesh
Contributor
August 12, 2021

Below script returns distinct assignees but twice. And there maybe better version to this,

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger

def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
//def log = Logger.getLogger("Jira Log")
log.setLevel(Level.DEBUG)

def jqlSearch = "project = XYZ AND issuetype = 'Request' AND assignee in (membersOf(XYZ_Users)) AND status not in (Closed, Cancelled) AND updatedDate <= -7D"

SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.results.collect {issueManager.getIssueObject(it.id)}
issues.assignee.unique().each { issue ->

   }
 }
else{
log.error("Invalid JQL :" + jqlSearch)
}