How to bulk delete a specific Linktype

Mohamed Mehdi Mrad September 15, 2022

Hi,

I'm trying to bulk delete a specif issue link type for a project using ScriptRunner following this guide.

But It keeps deleting every links available on the project, can someone help me to refine it only deletes a specific link.

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 15, 2022

Hi @Mohamed Mehdi Mrad

The example provided in this discussion is to remove all links associated with one issue.

Could you please specify what link types you are trying to remove?

Thank you and Kind regards,

Ram

Mohamed Mehdi Mrad September 16, 2022

Hello,

I want to delete only a specific type of link (exp: "created by") not all of them.

Thank you.

Regards.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2022

Hi @Mohamed Mehdi Mrad

For your requirement, you could try the sample code below on the ScriptRunner Console:-

import com.atlassian.jira.component.ComponentAccessor

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueManager = ComponentAccessor.issueManager
def issueLinkManager = ComponentAccessor.issueLinkManager

def issue = issueManager.getIssueObject('MOCK-1')

issueLinkManager.getOutwardLinks(issue.id).each {
if (it.linkTypeId == 10202) { // Issue Link Type
issueLinkManager.removeIssueLink(it, loggedInUser)
}
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

If you observe the sample code above, a link type id is used to identify the specific link that is to removed from the particular issue MOCK-1.

Below is a screenshot of the ScriptRunner console:-

config1.png

To identify the link type id, you will need to go to the Issue Link type page and place the mouse of ver the edit link as shown below:-

issue_linking_config.png

In the sample code provided, I am testing it with the Causes / Is Caused By Issue Link Type.

Below are a few test screenshots for your reference:-

1. First, when the ticket is created, two types of Issue Links are added, i.e. causes and relates to.

test1.png

2. Upon running the code in the ScripRunner Console, as expected, only the cases link has been removed, and the relates to link is still retained.

test2.png

 

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram 

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 22, 2022

Hi @Mohamed Mehdi Mrad

Does this answer your question?

If yes, please accept the answer provided.

 

Thank you and Kind regards,

Ram

Mohamed Mehdi Mrad September 23, 2022

Hello,

Yes this is indeed what I want to do, thank you for your answer.

Regards,

Mehdi.

Matthew Garlock May 25, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ , This works for me if i want to delete links of a given link type from a single issue, but how would you modify the script to iterate through a list of issues resulting from a JQL query/saved filter?

Suggest an answer

Log in or Sign up to answer