Removing Self as a Watcher on Transition

Our engineering group would like to un-watch tickets that they move over to QA.  The problem is that the current assignee needs to move the issue over to the new workflow step that indicates that the issue is ready for QA.  The problem is that the workflow step also removes the assignee, so I've been trying to grab it from a user field called "Last Developer".  When I use this field, I'm getting a null user even when I re-index the issue beforehand.  The script to set this custom field is a predefined Scriptrunner script.

 

When I use both the "Last Developer" custom field, as well as the assignee (I tried changing the order around).  I'm logging that the watcher is removed, but the previous assignee is still a watcher at the end of the transition.

 

Am I missing something?  Is there a particular step in the workflow post functions that I need to have this script in?  I have admin rights in the project so the manage watchers permission shouldn't be the problem.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.customfieldvalue.CustomFieldValue
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.atlassian.sal.api.user.UserManager


//reindexes issue prior to clearing watchers as otherwise the custom field is not persisted to DB
def indexManager = ComponentAccessor.getComponent(IssueIndexingService)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
indexManager.reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing);

//sets managers
def watcherManager = ComponentAccessor.getWatcherManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()

//grabs the developer object and user
def getLastDevObj = customFieldManager.getCustomFieldObjectByName("Last Developer")
def lastDevUser = userManager.getUserByName(issue.getCustomFieldValue(getLastDevObj).toString())


//clears the watcher
watcherManager.stopWatching(lastDevUser,issue)

1 answer

0 vote

I think you are probably not missing anything, except that there is a JIRA event listener built-in which always adds the current user as a watcher. That can be disabled per user, but only for all issues.

The order that listeners fire in is non-deterministic (I think), so chances are the JIRA one is coming after your one. Actually this is a workflow function, so definitely after.

If that's not the problem it might be to do with the types of user... is this JIRA 6.x?

Thank you for getting back to me.  We're currently running JIRA 7.1.4.  I've tried adding the workflow function after the Generic Event in the workflow, but I'm assuming that the listener is still picking up the watcher assignment after the transition.

Is there any way we can work around this without making huge changes?  If not then that's fine, but I don't know of another way to manage watchers in the workflow step.

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...

180 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