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

RemoveIssueLink Post Function

Total Company June 2, 2014

Dear Jamie,

I'm trying to make a post function script in the workflow to remove the issue links.

My goal is to remove an issue link when the status changes in Project 1 from B (In progress) to C (validation).

Why? There is a syncronizer running between the linked issue in Project 1 and 2. Project 1 is a big management project and project 2 (3, 4, 5, 6 ....) are application backlogs. When an issue is closed in the application backlog then the status in Project 1 can go to "validation". There is a possibility that the validation will disagree with the evidence and rejects the issue and puts it back to "In Progress".

Because we want to keep a history (for training purposes) we don't want to recreate an issue in the application backlog but make a new one. When we're progressing that issue in a new backlog item the other backlog item is also synchronize because it is still linked.

Is there a script that automatically removes the link in project 1 when changing the status from "In progress" to "Validation"? ( >> issueLinkManager.removeIssueLink (issue.getId()) << )

Thanks in advance!

Friendly Regards,

Tom

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
JamieA
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.
June 3, 2014

Dear Total Company.

You want something like this, completely untested:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.PropertiesManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext()?.getLoggedInUser()
def linkCallback = {IssueLink link -&gt;
    if (link.destinationObject.projectObject.key == "SOMEKEY") {
        issueLinkManager.removeIssueLink(link, user)
    }
}

issueLinkManager.getOutwardLinks(issue.id).each (linkCallback)
issueLinkManager.getInwardLinks(issue.id).each (linkCallback)

AndrewB October 8, 2015

TY Jamie - this worked for a similar scenario, with this example you just have to use 'def user = ComponentAccessor.getJiraAuthenticationContext()?.getUser().getDirectoryUser()' instead - at least now.

JamieA
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.
October 8, 2015

right... getUser().getDirectoryUser() should be the same as calling getLoggedInUser() pre jira 7. In jira 7 Atlassian has sorted out the user schizophrenia.

AndrewB October 8, 2015

Seeing weird behavior with this though - I log when a link is found in the linkCallback and also when the condition is met. Every time I make the transition the link I want to remove is found and the condition is met. However, the first time I make the transition the link isn't remove (at least on the UI), I have to make the transition again on the issue and then the link gets removed. Any ideas?

JamieA
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.
October 8, 2015
AndrewB October 8, 2015

Interesting, well I don't know exactly what is causing the issue, but as workaround I'm calling issueLinkManager.getOutwardLinks(issue.id).each (linkCallback) twice and it seems to be working fine now.

0 votes
Total Company June 9, 2014

Dear Jamie,

Thanks for your response.

Is it possible to only remove one specific link?
I know use;
- Details
- is realized by
- Mentions

Is it possible to only remove the Realizes link?

Friendly regards,

Tom

JamieA
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.
June 10, 2014

Yeah you just need to filter further by adding more "if" conditions. For link type use, link.issueLinkType.name or something.

TAGS
AUG Leaders

Atlassian Community Events