Get issue split link in postfunction

Jakub Cieplinski December 23, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 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()) 
Jakub Cieplinski December 27, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 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.

Jakub Cieplinski December 29, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 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)
Jakub Cieplinski January 2, 2022

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 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.

Jakub Cieplinski January 9, 2022

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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