Forums

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

Script Listener to Monitor User Group

Stephen Marsh April 25, 2018

I am trying to create a script listener that sends an email notification when ever a group has users added or deleted. This looks like its possible using the 'GroupMembershipCreatedEvent' but i am wondering whether i could include the user ID of any user added/deleted on the email notification that's fired? Does anyone think that this is possible?

1 answer

1 vote
Aleksandr Zuevich
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.
April 26, 2018

Hi Stephen,

If you want to send mail from an event not related to an issue, such as when a user is added, you can use a Custom Listener configure to handle the appropriate event, and a script such as this:

        import com.atlassian.crowd.event.group.GroupMembershipCreatedEvent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem

def event = event as GroupMembershipCreatedEvent

def email = new Email("a.zuevich@ya.ru")
email.setSubject("Subject")
email.setBody("User ${event.entityName} has been added to ${event.groupName}")
// email.setMimeType("text/html") // for messages with an html body

SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.getMailQueue().addItem(item)
Mike Rathwell
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.
January 3, 2019

@Aleksandr Zuevich this little snippet just got me out of a world of hurt from a rather paranoic group (merely added an if statement to check if their group was the one acted on)

Lacey Also July 14, 2021

@Mike Rathwellwhat was the line you added to see which group was acted upon?

Suggest an answer

Log in or Sign up to answer