Post Function Script - Clone Issue Error

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.

3 answers

1 accepted

This widget could not be displayed.

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

This widget could not be displayed.
Steven Behnke Community Champion Sep 11, 2015

How/why are you writing scripts without access to the logs? You cannot see if you're screwing anything up that way...

This widget could not be displayed.
Steven Behnke Community Champion Sep 11, 2015

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);
}


Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

255 views 5 0
Join discussion

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