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

Get users from email group to add as watchers

Alex Cumberland
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.
November 13, 2019

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Alex Cumberland
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.
November 20, 2019

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)
}

TAGS
AUG Leaders

Atlassian Community Events