Forums

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

Reporters Groups but with specifics

Marc Jason Mutuc
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2020

I was able to create a scripted field getting the groups of the reporter. Below is the script:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager

def groupManager = ComponentAccessor.getGroupManager()
def GroupList = groupManager.getGroupsForUser(issue.reporter)

return GroupList

However, I only want to get specific groups with the name starting with "Team". Can I get some help on how to do this please? 

Also, I'm getting this error messsage when I'm trying to create an issue and the field is not applied to a screen:

Exception occurred: com.atlassian.plugins.rest.common.json.JsonMarshallingException: org.codehaus.jackson.map.JsonMappingException: No serializer found for class com.atlassian.crowd.embedded.impl.ImmutableGroup and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.atlassian.jira.quickedit.rest.api.field.QuickEditFields["createdIssueDetails"]->com.atlassian.jira.rest.v2.issue.IssueBean["fields"]->java.util.HashMap["customfield_24609"]->com.google.common.collect.RegularImmutableSet[0])

1 answer

1 accepted

0 votes
Answer accepted
Marc Jason Mutuc
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2020

Currently using this

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()
def groupList = groupManager.getGroupsForUser(issue.reporter)

def groupNamesFiltered1 = groupList.findAll{ it.name.contains("A") }
def groupNamesFiltered2 = groupList.findAll{ it.name.contains("B") }

//Combine the two filtered lists by adding it the latter to the former

groupNamesFiltered1.addAll(groupNamesFiltered2) //Check if the list has values and then expand the list to a list of group names, convert to a string joined by commas
return groupNamesFiltered1 ? groupNamesFiltered1*.name.join(",") : null

Still looking for a cleaner script

Marc Jason Mutuc
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 3, 2020

Got a cleaner script from the support team:

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()
def groupList = groupManager.getGroupsForUser(issue.reporter)

def unwantedGroups = ["A","B"]

def groupNamesFiltered = groupList.findAll{ (it.name.contains("Dev") || it.name.contains("Stream")) && ! ( it.name in unwantedGroups ) }

return groupNamesFiltered ? groupNamesFiltered*.name.join(",") : null

Suggest an answer

Log in or Sign up to answer