Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Remove clone issues links for a issue

Hi ,I'm writing the script to remove the clone links for an issue in the same project.It seems script complied with no errors but the clones issue links are not removing.can you please suggests.

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.link.IssueLink

import com.atlassian.jira.user.ApplicationUser

 

ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

for(IssueLink link: ComponentAccessor.getIssueLinkManager().getIssueLinks(issue.getId())){

    if(link.getIssueLinkType().getName().equals("Clones"))

    ComponentAccessor.issueLinkManager.removeIssueLinks(issue, currentUser)

}

1 answer

1 accepted

0 votes
Answer accepted

Hi @srinivas_kattla ,

first of all - please check the name of the link in administration - "Clones" is probably wrong and you have to replace it with "Cloners"

links.png

Method removeIssueLinks will remove all the links, not only the one for clone, so probably you should use removeIssueLink instead.

I would recommend you to add some debug code to be able to find out, if you are getting any issue links at all.

Also method getIssueLinks expects to get link type id (not issue id), so I would recommend you to replace it.

Where did you put your code? Is this a post function in your workflow?

Code below works for me, but I'm not sure, if it will be good enough for your use case, maybe some more modifications will be needed.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser

ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().equals("Cloners")) {
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}

 

Hi @Hana Kučerová  , Thanks for your input. I will test it and updates as per the need. I'm adding this in post function. 

1111.PNGHi @Hana Kučerová  : I was able to work it out for issuelink type cloners but for other issuelinktype the script is not working .Can you please suggest

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser

ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().equals("System Test Execution") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}

issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().equals("System Test Execution") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().contains("Test") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}

issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().contains("Test") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}

Hana Kučerová Community Leader Jan 15, 2020

Hi @srinivas_kattla ,

it seems to me, that the script should work. Did you try it without the condition

issue.issueType.name == 'Story'

, i. e. for all types of issues?

Like srinivas_kattla likes this

I tried this but it is removing all issue.links for issuelink type. This should not happen .It should only remove the destination issuelinke type story which is linked. please suggest

Hana Kučerová Community Leader Jan 17, 2020

Hi @srinivas_kattla ,

so, you are trying to remove all the issue links, which meet two requirements:

  • the issue link has specific name
  • the linked issue has the type Story

Am I right?

If so, please try this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser

final ISSUE_LINK_NAMES = [
"System Test Execution",
"Test",
]

final ISSUE_TYPE_NAME = "Story"

ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()

issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
String linkedIssueType = issueLink.getSourceObject().getIssueType().getName()
String issueLinkName = issueLink.getIssueLinkType().getName()
if (ISSUE_LINK_NAMES.contains(issueLinkName) && linkedIssueType == ISSUE_TYPE_NAME) {
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}

issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->
String linkedIssueType = issueLink.getDestinationObject().getIssueType().getName()
String issueLinkName = issueLink.getIssueLinkType().getName()
if (ISSUE_LINK_NAMES.contains(issueLinkName) && linkedIssueType == ISSUE_TYPE_NAME) {
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,608 views 22 33
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you