De- Linking an Issue

i am writting an Groovy Script for post function, My question is: I have created a issue link, now on certian transition i want that link to get De-Link, So for it My approach is to grab that issue link and then do the de-link for both the issues. But i don't know how to grab the Issue Link ID.

Can any of thee geniouses out there can help me out?

2 answers

1 accepted

to get the issue link id's bi-directionally as follows

to get OUward links

List<IssueLink> allOutIssueLink = issueLinkManager.getOutwardLinks(sourceIssue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
	IssueLink issueLink = (IssueLink) outIterator.next();
	System.out.println(issueLink.getIssueLinkType().getId());	
}

same way to get inword issueLink's

List<IssueLink> allInIssueLink = issueLinkManager.getInwardLinks(sourceIssue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
	IssueLink issueLink = (IssueLink) inIterator.next();
	System.out.println(issueLink.getIssueLinkType().getId());
if (issueLink.getIssueLinkType().getId() == 10) {
Issue destinationIssue = issueLink.getDestinationObject();
}
 }

Once i gether the issue links,

I want to delink it and make the associated issue to move back to some other status.

I have tried using Inward issue, I am getting the Inward issue name and ID but i want an issue which is linked to it, So any thoughts on it?

you have to use following code to get linked issues

Issue issue=issueLink.getDestinationObject();

check my answer i have update the inword issuelink code

i have already given code to delink right?

issueLink = issueLinkManager.getIssueLink(sourceId, destId, linkType);
 
issueLinkManager.removeIssueLink(issueLink , remoteuser);

is it not worked?

Rambanam: Yes, I know and have implemented it and its working perfectly fine, since i have used Customfield plugin on 1 issue type through whcih i used to gather that custom field and make it as mutable issue and perform operations, But this plugin was implemented only on 1 issue type but i am trying to write a groovy script for other issue type, such that Bi-Directional functionality works,

So now since i have created a links between 2 issues, I want to grab issue link ID and then perform operations like setting Status and delinking.

So my motive is:

1) Gather the linked issue
2) Gather the current status of the issue
3) Look about the other linked status of the issue
4) Replace the issue's status from the current to the newest status (that you are looking to place)
5) update the issue

you are asking about delink or move status?

So any thoughts about this.

I am trying to use the inward link but still its giving me the link name and ID of itself,

my code goes like this:



log.warn("Current Issue is : " + issue)

List<IssueLink> allInIssueLink = linkManager.getInwardLinks(issue.getId());
for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
log.warn("Issue Link Type is : " +issueLink.getIssueLinkType().getId());
log.warn("Issue Link Name : " + issueLink.getIssueLinkType().getName())
Issue issue1= issueLink.getDestinationObject()
}


Collection<IssueLinkType> issueLinkTypes = ((IssueLinkTypeManager) ComponentManager
.getComponentInstanceOfType(IssueLinkTypeManager.class)).getIssueLinkTypes();
String linkID=null;
for (IssueLinkType linktype : issueLinkTypes) {
String name=linktype.getName();
if(name.equals("Open Position - Candidate Ticket")){
linkID=linktype.getId();
break;
}
}


}


OpenPositionFinalVersion(issue)

did you print issue1 object?

try somethink like this

List&lt;IssueLink&gt; allInIssueLink = linkManager.getInwardLinks(issue.getId());
for (Iterator&lt;IssueLink&gt; inIterator = allInIssueLink.iterator(); inIterator.hasNext();) {
IssueLink issueLink = (IssueLink) inIterator.next();
log.warn("Issue Link Type is : " +issueLink.getIssueLinkType().getId());
log.warn("Issue Link Name : " + issueLink.getIssueLinkType().getName());
Issue issue1= issueLink.getDestinationObject();
log.warn("issue1 : " + issue1);
if(issue1!=null){
log.warn("issue1 Key: " + issue1.getKey());
}
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

125 views 4 9
Read article

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