Forums

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

Disable autowatch using script listener

mani@123
Contributor
August 23, 2019

Hello All,

I have used below script in script listeners to disable autowatcher for reporters for a particular project.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.preferences.PreferenceKeys

def userManager = ComponentAccessor.getUserManager()
def preferencesManager = ComponentAccessor.getUserPreferencesManager()
userManager.getUsers().each {
user ->;
if (! preferencesManager.getPreferences(user).getBoolean(PreferenceKeys.USER_AUTOWATCH_DISABLED)) {
preferencesManager.getPreferences(user).setBoolean(PreferenceKeys.USER_AUTOWATCH_DISABLED, true)
}
}

But it is disabling for all the projects. when user creating issues in other project they are not automatically added to the watcher field.

Is it possible to limit disabling autowatcher for reporters for a single project??

Thanks in Advance,

Manikanta

1 answer

0 votes
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2019

because it's a user's setting, so it has a global context, you either autowatch issues or not.

I think you can rewrite listener to remove a reporter from watchers and limit the projects you want via the listener's context

The listener might look like this(on IssueCreated event):

import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue
def watcherManager = ComponentAccessor.watcherManager
def watchers = watcherManager.getWatchersUnsorted(issue)
def reporer = issue.reporter
if (reporter in watchers) {
watcherManager.stopWatching(reporer, issue)
}
mani@123
Contributor
August 26, 2019

Hi Turov,

Thanks for the reply!

I have added the script in the script listeners for issue created event. However, still autowatch is disabled for all projects.

It is showing below error in line 7 & 8:

autowatch.PNG

 

Below error in the logs:

2019-08-26 14:08:03,302 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-08-26 14:08:03,302 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
groovy.lang.MissingPropertyException: No such property: reporter for class: Script338
 at Script338.run(Script338.groovy:7

Thanks in advance,
Manikanta

Suggest an answer

Log in or Sign up to answer