Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove all watchers from an issue with ScriptRunner?

Markus W_ BENES
Contributor
July 21, 2023

Hello to all in the community :) how can i remove all watchers from a ticket; actually iam trying this code, but its not working; i have imported all needed scripts correct; i get the watchers and need a way to search/find them in the usermanager. seems that there is my problem.

def watchers = ComponentAccessor.watcherManager.getWatchers(issue, english).getEmailAddress()
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()

watchers.each{userName->
def user=ComponentAccessor.userManager.getUserByName(userName)
watcherManager.stopWatching(user, issue)
}




2 answers

1 accepted

2 votes
Answer accepted
Evgenii
Community Champion
July 21, 2023

Hi, @Markus W_ BENES 

Try this code please:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

List<ApplicationUser> watchers = ComponentAccessor.watcherManager.getWatchers(issue, Locale.US)
WatcherManager watcherManager = ComponentAccessor.getWatcherManager()

watchers.forEach { ApplicationUser user ->
watcherManager.stopWatching(user, issue)
}
0 votes
Markus W_ BENES
Contributor
July 21, 2023

Thank you! Runs perfect!

Suggest an answer

Log in or Sign up to answer