Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy watchers of source issue to its clones

Sibel February 15, 2019

Dear all ,

I have tried to use the following script via ScriptRunner 

As using "issue" i can get the new created issue but i could not find out how can i get the sourceIssue ?

Could you please assist?

( Jira v.7.12.1) 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.ComponentManager
import groovy.xml.MarkupBuilder
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;

Issue issue = issue // get currently created issue
Issue sourceIssue = issue // get source issue from linked issues, find by clone link type


WatcherManager watcherManager = ComponentAccessor.getWatcherManager();
Collection<ApplicationUser> userList = watcherManager.getWatchersUnsorted(sourceIssue);
for (ApplicationUser user : userList){
watcherManager.startWatching(user,issue);
}

 

1 answer

1 accepted

0 votes
Answer accepted
Ben Poulson
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.
February 15, 2019

Script that grabs the source issue as an issue object:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
def sourceIssue = issue
def linkMgr = ComponentAccessor.getIssueLinkManager()
def linkedIssues = linkMgr.getOutwardLinks(issue.id)
def sourceId = 0
Long cloneId = new Long(10001)//link type id of a cloned issue
for (link in linkedIssues)
{
if(link.issueLinkType.id == cloneId)
{
sourceIssue = link.destinationObject //Destination of the link is the original
//since jira doesn't create 1 bidirectional link, but instead two links,
//one for each issue. (i.e. a clone creates a link from the original to the
//clone, and a separate link from the clone to the original)
}
}

 

Note: If this doesn't work, it might be due to the clone id being wrong. To get the correct ID, run this script on an issue that was created as a clone, and replace 10001 in the above code with the output from this script for the cloned issue (Note: this script only works as is if it is run on the issue that was created as the result of a clone, not the original issue):

 

import com.atlassian.jira.component.ComponentAccessor
def linkMgr = ComponentAccessor.getIssueLinkManager()
def links = linkMgr.getOutwardLinks(issue.id)
String[] linkTypes = new String[links.size()+1]
linkTypes[0] = "Issue Key :: Link Type Id"
for (int i =0; i<links.size(); i++)
{
linkTypes[i+1] = links[i].destinationObject.key + " :: " + links[i].getLinkTypeId()
}
String format = ""
for (s in linkTypes)
format += s + "\n"
return format

 

Please let me know if that helped!

Sibel February 17, 2019

Thank you for your detailed explanation :) Worked ! our clone id is 10003.

Like Ben Poulson likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events