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])
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.