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

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

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

0 vote
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,323 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot