Delete linked issue when delete the original issue

Hello,

I'm trying to delete a linked issue, when I delete the original issue. I mean, I got a issue cloned and I want to delete both of them. I'm using a custom listener with ScriptRunner and this is my code.

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.crowd.embedded.api.CrowdService;
import com.atlassian.jira.issue.link.IssueLink

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def CrowdService crowdService = (CrowdService) ComponentManager.getInstance().getCrowdService();
def User currentUserObj = crowdService.getUser("admin")

issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
        def String linkname = issueLink.issueLinkType.getName();
        if (linkname.equals("Service desk")) {
  issueManager.deleteIssue(currentUserObj.getName(), issueLink.getDestinationObject(),
  EventDispatchOption.ISSUE_DELETED, false);
        }
}

 

I didn't get errors in the log.. but the issue cloned still exists.. How can I solve it?

 

Thanks in advance

Best Regards,

 

 

 

1 answer

0 vote
Vasiliy Zverev Community Champion Feb 15, 2016

There are inward and outward links. Are you sure that you use correct one here: issueLinkManager.getOutwardLinks(issue.id)? Do you loop these issues via this code?

Hello @Vasiliy Zverev,

 

The listener is limited to one project. I mean, the linked issue is in a different project and the listener will not be executed when will deleted.

I did some changes on my script, but still not working. I didn't get anything in the log..

 

import com.atlassian.jira.ComponentManager;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.crowd.embedded.api.CrowdService;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;

ComponentManager componentManager = ComponentManager.getInstance()
issueLinkManager = ComponentAccessor.getIssueLinkManager()
CrowdService crowdService = (CrowdService) ComponentManager.getInstance().getCrowdService();
User currentUserObj = crowdService.getUser("ejolgoo")
IssueManager issueManager = componentManager.getIssueManager()


issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
        String linkname = issueLink.issueLinkType.getName();
        Issue issue = issueLink.getDestinationObject()
        if (linkname.equals("Service desk")) {
            issueManager.deleteIssue(currentUserObj, issue, EventDispatchOption.ISSUE_DELETED, false);
        }
    }
Vasiliy Zverev Community Champion Feb 15, 2016
  1. You need to make sure that you get loot on requared issues. Try ScroptConsole via ScriptRunner and see this: https://answers.atlassian.com/questions/32982259

 

Can you print out the link type name and make sure it exactly matches the link type name. Perhaps add a screenshot of the "Issue Linking" config.

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 Tuesday in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

133 views 0 4
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