I am trying to automatically add watchers to certain issue types in a project on creation. Although the bug watcher plugin allows for a filter that would do this I can't enforce that users will create these filters. Thus I would like a script to do this at creation.
Adaptavist helped with a plugin that would do this but the plugin keeps getting in the way after about 4 different iterations.
I am running JIRA 7.x and this script should have worked
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def users = ["admin", "anuser"] //user keys of users you want to start watching the issue
Issue issue = issue
users.each { userKey ->
def userToWatch = userManager.getUserByKey(userKey)
if (userToWatch)
watcherManager.startWatching(userToWatch, issue)
else
log.warn "User with key ${userKey} is ot a valid user"
}
It was erroring out probably because of some hooks the issue watcher custom field from Bug watchers notification plugin was causing.
Does anyone have a suggestion on how I can get around this?