Forums

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

Use Scriptrunner to add user to group

Sngy October 1, 2020

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

1 vote
Answer accepted
Niranjan
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.
October 2, 2020 edited

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

Sngy October 2, 2020

Hi @Niranjan ,

it works now, thank you a lot!

0 votes
Vijay Sv
Contributor
May 5, 2021

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

}

}

Ankuskum
Contributor
December 13, 2021

Hello Vijay,

I want to check if the "Jira-users" group is used in the notification scheme or not.

If yes then send an email.

Can you please help me in that

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events