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,456,200
Community Members
 
Community Events
176
Community Groups

Get users from email group to add as watchers

Edited

JIRA Server 8.4.2

Adaptavist ScriptRunner for JIRA - 5.6.7.1-jira8

 

Wrote the following Postscript function on a transition to add watchers to a cloned issue.   It works fine as it is but if the users for this group changes then I have to change it manually instead of just depending on an update to an active directory email group.

I would like to be able to replace the users names with an email group from Active directory it can pull the users from.   So instead of "A_user", "B_user", & "C_user", I could use "Special User Notification Group" from Active directory of which these users are members.

 

************

import com.atlassian.jira.component.ComponentAccessor

doAfterCreate = {

           def watcherManager = ComponentAccessor.getWatcherManager()
           def userManager = ComponentAccessor.getUserManager()

           def watchUsers = {usernames ->

               usernames.each {def user = userManager.getUserByKey(it.toString())
                                           if (user) {watcherManager.startWatching(user, issue)}}
              }

      def users = ["A_User", "B_user", "C_user"]

      watchUsers (users)
}

 

************

Update since originally posted question:

 

Found that if I change the "def users" line to the following:

 

def users = groupManager.getUsersInGroup("Team1 Notification Group")

 

Then I get the users in the group by does not allow them to be added as watchers. Actually does not add any watchers at all to the issue.

 

In script console it returns as a result: 

 

[A_User(a_user), B_User(b_user), C_User(c_user)]

 

just not sure how to reference it in the loop so that it pulls the actual userId to add it as a watcher.

 

1 answer

1 accepted

1 vote
Answer accepted

Figured out one way to do it 

 

import com.atlassian.jira.component.ComponentAccessor

def groupManager = ComponentAccessor.getGroupManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()

def users = groupManager.getUsersInGroup("Team 1 Notifications")

for (member in users) {
        def user = userManager.getUserByKey(member.username)
         watcherManager.startWatching(user, issue)
}

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events