• Community
  • Products
  • Jira Core
  • Questions
  • Trying to script adding watchers in JIRA 7.1.7, WatcherManager.startWatching() is complaining about types DelegatingApplicationUser and IssueImpl

Trying to script adding watchers in JIRA 7.1.7, WatcherManager.startWatching() is complaining about types DelegatingApplicationUser and IssueImpl

I'm trying to add watchers after a Story is added in a project. I've been bouncing all over existing questions and sample scripts, but changes in JIRA versions have rendered all the examples I could find as deficient in one way or another.

Not sure where this is breaking since from what I can tell DelegatingApplicationUser is an implementation of ApplicationUser and IssueImpl is an implementation of Issue.

groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.issue.watchers.WatcherManager.startWatching() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, com.atlassian.jira.issue.IssueImpl) values: [johndoe(johndoe), ISS-01]

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.watchers.WatcherManager


def userManager = ComponentAccessor.getUserManager()
def watchUsers = {usernames ->
  usernames.each {
    def user = userManager.getUserByName("${it}")
      WatcherManager.startWatching(user, issue)
  }
}

def users = ["johndoe","janedoe"]


if(issue.getIssueType().name=="Story"){
  watchUsers(users)
}

 

 

2 answers

1 accepted

What the error says is that it cannot find such static method in WatcherManager - the key here being the word "static". The script is invoking startWatching() as a static method, it should be called on the instance instead:

def watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(user, issue)

Thank you! Went through so many iterations that I missed that.

Here is the final working code for anyone trying to get through this versioning hell as well, working as of v 7.1.7

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.watchers.WatcherManager


def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()


def watchUsers = {usernames ->
   usernames.each {
         def user = userManager.getUserByName("${it}")
         watcherManager.startWatching(user, issue)
      }
}


def users = ["johndoe","janedoe"]
if(issue.getIssueType().name=="Story"){
	watchUsers(users)
}

I wanted to use this script on the Create transition, but can't get it to work in JIRA 7.2.6. Any ideas? Error below.

 

2017-01-06 12:25:32,467 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-01-06 12:25:32,467 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210)
	at com.google.common.cache.LocalCache$LocalManualCache.invalidate(LocalCache.java:4764)
	at com.atlassian.jira.issue.watchers.DefaultWatcherManager.updateWatch(DefaultWatcherManager.java:168)
	at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:85)
	at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:76)
	at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source)
	at Script33$_run_closure1$_closure2.doCall(Script33.groovy:13)
	at Script33$_run_closure1.doCall(Script33.groovy:11)
	at Script33.run(Script33.groovy:20)

 

 

Here's the solution worked for me:  You can remove the Components condition.

GroovyRE.JPG

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

667 views 4 15
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot