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,560,000
Community Members
 
Community Events
185
Community Groups

Add user group as watchers of an issue using ScriptRunner custom listener

Hi, (especially @Kristian Walker _Adaptavist_ )

I am trying to create a custom listener that would add a specific user group, let's call it "INV" on a specific event.

The most similar use case I found is adding a project role as watchers.

I can't script this, could someone help me adjust the script to use a specific group?

Thanks a lot in advance,
Daniel

 

2 answers

1 accepted

3 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 11, 2019

Here is the script from the other post, modified to get group members instead of project role members, I haven't actually tried it. But it should work.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.security.roles.ProjectRoleManager

Issue issue = event.issue
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.userUtil


userUtil.getAllUsersInGroupNames(['INV']).each {user ->
    watcherManager.startWatching(user, issue)
}

It worked, amazing Peter, thanks so much :)

Hi Peter, would it be possible to modify this to use it for users in a specific Project Role, as an "On Create" post function? I've been trying to get it to work for my use case but having a hard time as I am inexperienced. Thank you regardless.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 25, 2023
1 vote
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 12, 2019 • edited

Hi Daniel,

I have tested the code provided by Peter in the response above using the latest version of ScriptRunner and Jira 7.13.1 and can confirm this code worked when I configured as a script listener on the issue updated event.

The code added all users in the INV group as watchers on an issue when it is updated and I would advise using the code provided by Peter to achieve your requirement ensuring you set it to run on the event that you require.

Regards,

Kristian

Thanks for testing Kristian, indeed it worked for me :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events