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

Your Points Tracker
Challenges
Leaderboard
  • 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
Recognition
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?
Kudos
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

Use Scriptrunner to add user to group

I'm searching for a solution that gives me an opportunity to add the user from Custom Field to specific JIRA Group by a post-function workflow or a listener.

I saw solutions like the following example in the community, but this does not seem to work anymore; the addUserToGroup method is not recognized.

 

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()

def user = "Neuling"

def group = groupManager.getGroup("Group1")

groupManager.addUserToGroup(user,group)

 

Thanks in advance!

 

 

 

 

 

2 answers

1 accepted

0 votes
Answer accepted

Hi @Sngy ,

Kindly check this link for script to remove users from group

 

https://library.adaptavist.com/entity/remove-specified-users-from-a-group

 

Replace "removeUserFromGroup" with "addUserToGroup" and "userToRemove" with "userToAdd". It should work

Hi @Niranjan ,

it works now, thank you a lot!

This might help....

 

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")
return

}

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

}

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
TAGS

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