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) }
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) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's the solution worked for me: You can remove the Components condition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.