I'm adding a new transition to a resolved task that will spawn a ticket in our QA project. Basically, I want to clone the current issue, clear the assignee, and remove all the watchers. I've customized the "Additional issue actions" script to achieve this, but I keep running into errors on clearing out the watchers. The script is:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.watchers.IssueWatcherAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Locale;
ComponentManager componentManager = ComponentManager.getInstance()
def currentUser = componentManager.jiraAuthenticationContext?.user
issue.summary = 'QA: ' + sourceIssue.summary
issue.description = 'ORIGINAL ISSUE:\n' + sourceIssue.description
issue.assigneeId = ''
issue.reporterId = currentUser.name
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.getUserUtil()
MutableIssue missue = ComponentManager.getInstance().getIssueManager().getIssueObject(issue.getKey());
def watchers = watcherManager.getWatchers(missue,Locale.getDefault());
for (user in watchers){
watcherManager.stopWatching(user,missue);
}
I don't have access to any error logs, but script runs fine in the console (with issue.getKey() replaced with an actual issue string). The last four lines seem to be causing the headache as the transition succeeds with them removed.
Any and all help is greatly appreciated.
I think you may have a better chance of getting this answered in Developers, instead of Administration, but I might be wrong. However I do believe the Bob Swift "Update on Transition" and "Create on Transition" plugins could take care of this without any scripting on your end, if you happen to have a company credit card. ![]()
I noticed different code on a few related answers – Specifically:
for (ApplicationUser user in watchers){
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.watchers.IssueWatcherAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
import java.util.Locale;
ComponentManager componentManager = ComponentManager.getInstance()
def currentUser = componentManager.jiraAuthenticationContext?.user
issue.summary = 'QA: ' + sourceIssue.summary
issue.description = 'ORIGINAL ISSUE:\n' + sourceIssue.description
issue.assigneeId = ''
issue.reporterId = currentUser.name
def watcherManager = ComponentAccessor.getWatcherManager()
def userUtil = ComponentAccessor.getUserUtil()
MutableIssue missue = ComponentManager.getInstance().getIssueManager().getIssueObject(issue.getKey());
def watchers = watcherManager.getWatchers(missue,Locale.getDefault());
for (ApplicationUser user in watchers){
watcherManager.stopWatching(user,missue);
}You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How/why are you writing scripts without access to the logs? You cannot see if you're screwing anything up that way...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.