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

2 votes
Accepted answer

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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

413 views 0 3
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