Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner - Add multi users into a Group Edited

I want to add multi user into one group, So I came with script below:


import com.atlassian.seraph.auth.DefaultAuthenticator
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import java.util.ArrayList
import java.util.List
import java.lang.String

def userUtil = ComponentAccessor.getUserUtil()
def groupManager = ComponentAccessor.getGroupManager()
def group = groupManager.getGroup("Group1")
def user
def names = "A,B,C".split(",")
def arrayLength = names.length
for (def i =0; i < arrayLength; i++){
   user = userUtil.getUser(names[i])

But I got few error such as :

CannotCreateTransactionException: Could not create DirContext instance for transaction;


Please help me on this:

2 answers

1 accepted

0 votes
Answer accepted

Try this:

import com.atlassian.jira.component.ComponentAccessor

def grpMgr = ComponentAccessor.getGroupManager()
def usrMgr = ComponentAccessor.getUserManager()
def targetGroup = grpMgr.getGroup("group name")
ArrayList usersToAdd = new ArrayList()

for (int i = 0; i < usersToAdd.size(); i++){
grpMgr.addUserToGroup(usrMgr.getUserByName(usersToAdd[i]), targetGroup)

@Ivan Tovbin

I did try, get error as below.

Can not find matching method at line 10 column 3, 25.

@Qi Jiang

I imagine it's the static type checking which is not always accurate in ScriptRunner as per this doc. So in this very case you can simply ignore these errors. I've just tested it in my instance and it works just fine even though I get the same error message as you.

@Ivan Tovbin

i got error as below:

org.springframework.transaction.CannotCreateTransactionException: Could not create DirContext instance for transaction; nested exception is org.springframework.ldap.CommunicationException

@Ivan Tovbin

Hey Ivan,

I am starting error below:Can not find matching method com.atlassian.jira.user.UserManager#getUserByName(E)


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def groupManager = ComponentAccessor.getGroupManager()
def usrMgr = ComponentAccessor.getUserManager()
ArrayList usersToAdd = new ArrayList()
def group = groupManager.getGroup("ABC_Users")
def user

for (int i = 0; i < usersToAdd.size(); i++){
user = (ApplicationUser) usrMgr.getUserByName(usersToAdd[i])


Try This....


import com.atlassian.jira.component.ComponentAccessor

def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
final String groupName = "GROUPA" // the group you want to add users
def group = ComponentAccessor.groupManager.getGroup(groupName) // user names of the users to add
final List<String> userToAdd = ["USR1", "USR2", "USR3"]

userToAdd.each {
def usertoadd = userManager.getUserByName(it)
if (!usertoadd) {
log.warn("User: $userToAdd doesn't exist")


if (ComponentAccessor.getGroupManager().getGroupsForUser(usertoadd).contains(group)) {
log.warn("User: $usertoadd.username already in the group: $groupName")


if(!group) {
log.warn("Group: $groupName doesn't exist")

} else {

userUtil.addUserToGroup(group, usertoadd)
log.warn("User: $usertoadd.username added to the $groupName")



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

354 views 5 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you