Post function adding users to watchers

I am developing post function which adds users to issue watchers on a transition, but when executing the post function finished I am not able to remove added users from watchers, even when I am logged as Jira administrators and I have granted MANAGE_WATCHERS permission. On the issue view I am able to remove users from watchers dropdown, but when I refresh the page, they are still in the watchers list. I am using WatcherManager and here is my execute method:

    @Override
    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
        MutableIssue mutableIssue = getIssue(transientVars);
        ApplicationUser watcher = userManager.getUserByKey("tomek");
        if ((watcher != null) && !this.watcherManager.isWatching(watcher, mutableIssue)) {
                watcherManager.startWatching(watcher, mutableIssue);
        }
    }

I alse used the WatcherService but effect is the same.

Can anyone help me with this issue?

Hi Adrian,

I’m affected by the same problem.
The only way to remove de added watchers are by clicking remove+add+remove on user interface.
But I need to be able to remove watchers also programmatically using stopWatching() method.
Did you find a solution for this issue?

Regards.

Hi Adrian,

I encountered the same weird behaviour and spent a couple of hours, trying to figure out what happens. In the end I found out that it only occurs on auto-generated tickets (sample project). When I created a new Issue, everything worked as expected. Maybe for you too?

By the way, you should switch to the WatcherService, which internally uses the WatcherManager, but additionally checks the permissions if the user is allowed to watch.

Best regards
Sascha

Hi Manuel,
I didn’t find the solution. Maybe @ccsno advise will help you, I haven’t checked it yet.
Best regards,
Adrian

Hi,
I don’t remember if I tested it on auto-generated tickets but it’s possible. Thank you for your feedback, I will definitely check it in the free time and give you an answer.
Best regards,
Adrian