Get a list of watchers from an issue

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.IssueWatcherAccessor
import com.atlassian.jira.issue.watchers.WatcherManager

ComponentManager componentManager = ComponentManager.getInstance()
Issue issue = componentManager.getIssueManager().getIssueObject("EPIC-10")
User user = componentManager.getJiraAuthenticationContext().getLoggedInUser()
String recipient = ''
try {

    //Add comment to the original
    CommentManager commentManager = componentManager.getComponentInstanceOfType(CommentManager.class)

    def list = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObject("customfield_12117"))

    for (u in list) {
        if (recipient == ''){
            recipient = u.displayName
        }  else {
            recipient = recipient + ', ' + u.displayName
        }
    }
    IssueWatcherAccessor iwa = ComponentAccessor.getComponent(IssueWatcherAccessor.class)
    list =  iwa.getWatchers(issue, java.util.Locale)

    for (u in list){
        if (recipient == ''){
            recipient = u.displayName
        }  else {
            recipient = recipient + ', ' + u.displayName
        }
    }

    //   String comment = 'Epic has been sent to: ' + recipient + ' for approval.'
    //   commentManager.create(issue, user.getName(), comment, true)

    return 'For Approval Email has been sent to: ' + recipient + ' for approval.'
} catch(all) {
    return false
}

Returns error message...

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.watchers.DefaultIssueWatcherAccessor.getWatchers() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, java.lang.Class) values: [EPIC-10, class java.util.Locale] Possible solutions: getWatchers(com.atlassian.jira.issue.Issue, java.util.Locale), getWatcherKeys(com.atlassian.jira.issue.Issue)

1 answer

1 accepted

Hi Dean,

You should be given an instance of the java.util.Locale class as an argument in the method iwa.getWatchers(issue,...) .

Something like this :

Locale en = new Locale("en");

iwa.getWatchers(issue,en);

It's actually pretty clearly explained in the error message.

Best regards,

Peter

Thanks Peter - for some reason I completly missed that!

Peter, do you know why I would receive this error? Stack Trace: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getWatchersFor() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [SAND-1] Possible solutions: getWatches() . . . Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getWatchersFor() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [SAND-1] Possible solutions: getWatches() . . . Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getWatchersFor() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [SAND-1] Possible solutions: getWatches()

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

137 views 0 4
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