Post Function Script - Clone Issue Error

Mike Ginsburg September 10, 2015

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

0 votes
Answer accepted
Robert Anthony September 10, 2015

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 votes
Steven F Behnke
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.
September 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);
}


0 votes
Steven F Behnke
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.
September 11, 2015

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

Suggest an answer

Log in or Sign up to answer