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

DH September 3, 2016

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

1 vote
Answer accepted
Petar Petrov (Appfire)
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.
September 3, 2016

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)
DH September 3, 2016

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)
}
Rose Cruz January 6, 2017

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)

 

 

0 votes
Pritesh Jagani October 18, 2017

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

GroovyRE.JPG

SORIOT Mickaël March 2, 2018

It work's for me. Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events