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,293,626
Community Members
 
Community Events
165
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
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

215 views 0 6
Join discussion

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