It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

1 vote
Answer 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

It work's for me. Thanks

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

1,098 views 7 0
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you