Hello,
i want to use the script runner to add users to group.
I found this script for showing the users who are not in a group:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.user.util.UserUtilUserUtil userUtil = ComponentAccessor.getUserUtil() result = '' userUtil.getUsers().findAll { userUtil.getGroupsForUser(it.getName()).size() == 0} .each { u -> result += u.name + "<br>" } result
Here (https://docs.atlassian.com/jira/latest/com/atlassian/jira/security/groups/GroupManager.html) is see the method "addUserToGroup".
Is it possible to help me for programming the additional code, to add users to an existing group?
Would me help very much.
Thanks
It should be something like that:
import com.atlassian.jira.component.ComponentAccessor def userManager = ComponentAccessor.getUserManager() def groupManager = ComponentAccessor.getGroupManager() def group = groupManager.getGroup("Group1") userManager.getAllUsers().each { user -> groupManager.addUserToGroup(user,group) }
This code add all users to Group1
I needed to add more than 1000 users to a group, with a conditional before the function it worked like magic for me, Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Didn't work for me, it get the error below. ScriptRunner version 5.6.15.1-p5
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Brad, Replace
>
to
>
All codes we post here have this kind of character scape...
user -> groupManager.addUserToGroup(user,group)
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.
Thanks for your answer. It was to define the group before :)
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.