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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Get users from email group to add as watchers Edited

JIRA Server 8.4.2

Adaptavist ScriptRunner for JIRA -


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
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

292 views 5 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you