Find users in group. Add all members of group to another group. Scriptrunner

Raynard Rhodes
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.
August 2, 2019

I'm currently attempting to find all users in a group then add all of them to another group using scriptrunner. Below I am able to view the individuals in the initial group, but I am unable to add them to another. Below is currently what I have.

 

**edit** we are using crowd to manage our groups. These are not local groups.



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser

def groupManager = ComponentAccessor.getGroupManager()
def userManager = ComponentAccessor.getUserManager()
def usersInGroup = groupManager.getUsersInGroup("GRC-RefSeq")
log.warn(usersInGroup)
def systems = groupManager.getGroup("Systems")

for(people in usersInGroup){
//lost
}

 

1 answer

1 accepted

2 votes
Answer accepted
Raynard Rhodes
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.
August 5, 2019

I've figured it out.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.Group


def groupManager = ComponentAccessor.getGroupManager()
def userManager = ComponentAccessor.getUserManager()

def usersInGroup1 = groupManager.getUsersInGroup("THIS IS GROUP 1")
def usersInGroup2 = groupManager.getUsersInGroup("THIS IS GROUP 2")
log.warn(usersInGroup1)
log.warn(usersInGroup2)
def systems = groupManager.getGroup("ADD TO THIS GROUP")

Collection<ApplicationUser> Group1 = usersInGroup1
Collection<ApplicationUser> Group2 = usersInGroup2

for (ApplicationUser Users1 : Group1){
groupManager.addUserToGroup(Users1,systems)
}

for (ApplicationUser User2 : Group2){
groupManager.addUserToGroup(User2,systems)
}

Suggest an answer

Log in or Sign up to answer