Removing Self as a Watcher on Transition

Stuart King May 16, 2016

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 votes
JamieA
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.
May 20, 2016

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?

Stuart King May 20, 2016

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
TAGS
AUG Leaders

Atlassian Community Events