Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,462,000
Community Members
 
Community Events
176
Community Groups

scriptRunner Listeners : how to delete/remove user-group

Edited

hi,

    I would like to use an issue manage an user-group.

import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import java.util.List;

log.setLevel(org.apache.log4j.Level.DEBUG);

def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def eventTypeManager = ComponentAccessor.getEventTypeManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changes = changeHistoryManager.getAllChangeItems(issue)

def eventTypeName = eventTypeManager.getEventType(event.eventTypeId).getName()
log.debug("EVENT TYPE NAME --> "+ eventTypeName)

def members_cf = customFieldManager.getCustomFieldObjectByName("members")
List<ApplicationUser> members = issue.getCustomFieldValue(members_cf)
log.debug "members:" + members

def groupName = issue.getSummary()
log.debug "groupName:" + groupName


if (issue.getIssueType().name == 'groupName') {
if (groupManager.groupExists(groupName)) {
// DeleteGroup(groupName)
}

if (issue.getStatus().name=='active'&&eventTypeName!='delete event') {
groupManager.createGroup(groupName)
def group = groupManager.getGroup(groupName)
log.debug "group:" + group
users.each { user -> groupManager.addUserToGroup(user, group) }
}
}

This line " // DeleteGroup(groupName)", how to do it.

 

Thanks

1 answer

1 accepted

1 vote
Answer accepted
Vishwas Rising Star Jan 25, 2022

Hey @ninghongju 

Welcome to Atlassian Community !!

Please check this script from adaptavist here https://library.adaptavist.com/entity/delete-groups-in-jira has an example of removing groups.

Also check this thread here this might help https://community.atlassian.com/t5/Jira-questions/Bulk-delete-groups-in-JIRA-using-Scriptrunner/qaq-p/1098530

 

Regards,

Vishwas

it's worked! Thanks so much!

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.core.util.StaticCrowdServiceFactory


def groupManager = ComponentAccessor.getGroupManager()
def crowdService = StaticCrowdServiceFactory.crowdService

def group = groupManager.getGroup('groupName')
crowdService.removeGroup(group)

Like Vishwas likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events