How to automatically add watchers when you have the bug watcher notification plugin installed

Pat Noack October 5, 2016

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?

 

2 answers

0 votes
Jonny Carter
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.
October 5, 2016

You're right... the script should work. Maybe provide the errors being thrown by the Bug Watchers Notification plugin? That may suggest a workaround.

0 votes
TSD Group October 5, 2016

Hi Pat!

We are using for your case two different plugins: JIRA Watcher Field and JIRA Suite Utilities. They both are free. First allows create a custom field of users type which is connected with Watchers. The second one allows automaticly update custom fields and also this field. So user is added to the watchers on creation transition in the workfow you want.

Pat Noack October 5, 2016

I have both of those plugins and life would probably be easy for me if it wasn't for the Bug watcher notification plugin which is making the watchers part of most scripting behave differently.  I'm certain if I wasn't using this plugin that I could get the script to work.

Thank you for your answers.

 

TSD Group October 5, 2016

You want to say 'Bug watcher' impedes 'JIRA Suit' from update watchers field?

Pat Noack October 5, 2016

That appears to be what is happening.  NOTE:  The bug watcher program allows individuals the ability to set a filter and become a watcher when any ticket with a certain criteria is created.  If I could get my end users to do as I ask I wouldn't need to do it in the workflow with this plugin however the plugin does appear to be giving me issues when I try to program the action in a transition.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events