Forums

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

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
}

 

2 answers

1 accepted

3 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)
}
0 votes
Dang Thi Thuy Tien
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.
February 3, 2025

Hey there!
With Group Master for Jira. You can quickly add, remove, or update members—all from one place with bulk users ;) with UI, no need script anymore :v 

Try it out and make group management smooth and simple!
https://marketplace.atlassian.com/apps/1236395/group-master-for-jira?hosting=datacenter&tab=overview

And another advanced group management capabilities:
    View group usage across Jira
    Edit group names for clarity
    Move or copy group members easily
    Replicate or migrate group usage
    Delete groups and clean up associated data 

Suggest an answer

Log in or Sign up to answer