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.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.