We are using a variation the script in https://library.adaptavist.com/entity/remove-specified-users-from-a-group to add a user to a specific group when an issue is created through our service desk portal. Any idea how we could add the same user to groups selected in a group picker field?
Hi @Manuel Valcarcel
Try the following. I tested it on my instance and works just fine!
import com.atlassian.jira.component.ComponentAccessor// the group you want to remove users fromdef groups = ["group1", "group2"]// user names of the users to addfinal List<String> usersToAdd = ["admin"]def userUtil = ComponentAccessor.userUtildef userManager = ComponentAccessor.userManagerArrayList<com.atlassian.crowd.embedded.api.Group> finalGroups = new ArrayList<com.atlassian.crowd.embedded.api.Group>(groups.size())for (group in groups){ finalGroups.add(ComponentAccessor.groupManager.getGroup(group)) assert group : "Could not find group with name $group"}usersToAdd.each { def userToAdd = userManager.getUserByName(it) userUtil.addUserToGroups(finalGroups, userToAdd)}
Let me know if that worked for you as well!
It looks like you're new here. Sign in or register to get started.