Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Get issue split link in postfunction

Hello,

 

When splitting an issue I want to get the "split from" linked issue in the "Create" postfunction. However, the returned link list is empty

 

il = ComponentAccessor.getIssueLinkManager()


links = il.getOutwardLinks(issue.getId()) // this list is empty

 

I'm using JSS plugin, I've put my postfunction after the reindexing step of workflow but it doesn't work. Where should i attach my postfunction for links to be visible?

 

What I want to ultimately achieve is to copy some customfields from original issue to the split one.

1 answer

0 votes
Antoine Berry Community Leader Dec 27, 2021

Hello @Jakub Cieplinski ,

Your script should be working with the split issue function. 

You should probably put the post function as the last one in the transition to make sure the link is created. Also remember that there two ways in a issue link, so you might want to try : 

 

links = il.getInwardLinks(issue.getId()) 

Hi, I've also tried to get Inward links, didn't work. I've tried putting the postfunction in each place after the "create original issue" step and it doesn't work

Like Antoine Berry likes this
Antoine Berry Community Leader Dec 29, 2021

Hi,

Could you please add a screenshot of your create issue post functions and describe your process - mainly how you create your linked issue and how it visually appears on the source issue.

image.pngimage.pngimage.png

Im using "Split issue" functionality to split issue into two, this creates "splits from" and "splits to" links. I've linked the pf to issue Create step and it is called when split issue is created.

The relevant code is in the screenshot, I'm purposefully raising an exception there to see in logs if any links were captured(they are not)

Antoine Berry Community Leader Dec 31, 2021

Hi @Jakub Cieplinski ,

I replicated your context, with the only difference that I am using a groovy script (using scriptrunner plugin) as I don't have the Jython plug-in. This is the script I am using to retrieve all linked issues if that can help : 

import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;

def issues = []
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
def linkedIssue = issueLink.getDestinationObject()
issues << linkedIssue
}

List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
;
def linkedIssue = issueLink.getDestinationObject()
issues << linkedIssue
}

log.error("issues : " + issues)

So with script runner custom plugin it just works like this? Good to know.

We will be migrating to scriptrunner this year and I've managed to do it as a listener. Which approach do you think would be better, as a listener for IssueLinkCreatedEvent or a post function on create? I'm asking in terms of performance etc.

Antoine Berry Community Leader Jan 03, 2022

Hi @Jakub Cieplinski ,

I think a listener would be better as it will only trigger when an issue is linked as opposed to every time an issue is created.

Hi @Antoine Berry 

Thanks for help, I'm going to go with the listener approach.
However, I have a question, after which step did you put the scriptrunner postfunction? I've copied your script verbatim just to see if it would work and... it doesn't. No links are returned either for allInIssueLink or allOutIssueLink

Like Antoine Berry likes this
Antoine Berry Community Leader Jan 21, 2022

Hi @Jakub Cieplinski ,

I have setup this script as the last post-function in the create transition. When I clone an issue, this script will trigger and return the cloned issue.

Suggest an answer

Log in or Sign up to answer
TAGS

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