Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue Linking Question - Need Help

MAG-II
Contributor
June 17, 2019

Hello - 

I am in a tough situation regarding Issue linking. In my Jira instance I have an Issue that automatically creates 2 different linked Issues (on separate workflows) via post function early in my project. This works well.

Later in my workflow the main Issue, which is currently linked with 2 other Issues, creates a third linked Issue. With this third linked Issue I am trying to figure out a way to link this third Issue with my 2 existing Issues that are linked with my main Issue. Is such a configuration possible in Jira?

My apologies if I am not being very clear. The situation is a bit confusing. Any help would be much appreciated.

1 answer

0 votes
Ilya Turov
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 17, 2019

Hello, it's totally achievable. Depends which plugins you've got.

If you have a scriptrunner (or I believe SIL might have the same functionality), you can write you own postfunction to create needed links. But maybe some other plugins can do it out of their box, can't be sure.

MAG-II
Contributor
June 17, 2019

Hey thanks for the response. Glad to know that such a configuration is possible. I have ScriptRunner, JMWE, and Jira Workflow Toolbox add-ons.

If it's the script route, how would I begin to write something like that? My knowledge of Groovy is a bit limited. Would be very grateful for some insight there.

Also, could any kind of JQL possibly achieve this?

Ilya Turov
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 17, 2019

quicly typed something like this, definitely needs tuning, but I hope you get the idea:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//here i assume you only have three linked issues, otherwise you need to find them
def linkedIssues = issueLinkManager.getLinkCollectionOverrideSecurity(issue).allIssues
def oldLinkedIssues = linkedIssues.findAll {
//here we somehow find those two. maybe by their type or project
it.issueType.name == "some type" || it.projectObject.key == "PRJ"
}
def newLinkedIssue = linkedIssues.find {
//here again we need to somehow find that issue
it.issueType.name == "maybe another type"
}
linkedIssues.each {
//practice here with swapping sourceid and destination id to make a proper link
def sourceIssueId = newLinkedIssue.id
def destinationIssueId = it.id
//find link type id you want from your system
def issueLinkTypeId = 12345
issueLinkManager.createIssueLink(sourceIssueId, destinationIssueId, issueLinkTypeId, 0L, currentUser)
}

issueLinkManager  is your bro here 

first you use it to find linked issues with methods like getLinkCollectionOverrideSecurity or getInwardLinks/getOutwardLinks and then you just create new links with createIssueLink

Just be sure you place it after the postfunction which creates your third issue so it already exists

MAG-II
Contributor
June 18, 2019

Good Morning IIya - 

I attempted to use the script you provided as in the post function of the Create Issue transition for my 3rd Issue that I am trying to link with the two existing linked Issues. So far I am not having any luck. Below is the script I have:

 

 

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//here i assume you only have three linked issues, otherwise you need to find them
def linkedIssues = issueLinkManager.getLinkCollectionOverrideSecurity(issue).allIssues
def oldLinkedIssues = linkedIssues.findAll {
//here we somehow find those two. maybe by their type or project
it.issueType.name == "Test1, Test2" || it.projectObject.key == "VTEST"
}
def newLinkedIssue = linkedIssues.find {
//here again we need to somehow find that issue
it.issueType.name == "Test3"
}
linkedIssues.each {
//practice here with swapping sourceid and destination id to make a proper link
def sourceIssueId = newLinkedIssue.id
def destinationIssueId = it.id
//find link type id you want from your system
def issueLinkTypeId = 10003
issueLinkManager.createIssueLink(sourceIssueId, destinationIssueId, issueLinkTypeId, 0L, currentUser)
}

 

 

For issuetype.name, "Test1" and "Test2" are the two different Issue Types for the existing linked Issues. "Test3" is the Issue Type for the 3rd linked Issue that I am trying to link with the post function.

Regarding your comment "//practice here with swapping sourceid and destination id to make a proper link," I am not exactly sure what I can do here.

 

I found the issueLinkTypeId (10003) from the Jira Issues>Issue Linking section (found in the url of the page). I'm sure that there's a lot that I am missing here. Any ideas?

Ilya Turov
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 18, 2019

@MAG-II 

there wasn't really much to fix, only the part where you check linked issue to belong to one of a two issue types:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//here i assume you only have three linked issues, otherwise you need to find them
def linkedIssues = issueLinkManager.getLinkCollectionOverrideSecurity(issue).allIssues
def oldLinkedIssues = linkedIssues.findAll {
//here we somehow find those two. maybe by their type or project
it.issueType.name in ["Test1", "Test2"] || it.projectObject.key == "VTEST"
}
def newLinkedIssue = linkedIssues.find {
//here again we need to somehow find that issue
it.issueType.name == "Test3"
}
linkedIssues.each {
//practice here with swapping sourceid and destination id to make a proper link
def sourceIssueId = newLinkedIssue.id
def destinationIssueId = it.id
//find link type id you want from your system
def issueLinkTypeId = 10003
issueLinkManager.createIssueLink(sourceIssueId, destinationIssueId, issueLinkTypeId, 0L, currentUser)
}

as for my comment, I meant that there's a direction where link goes, eg one issue is going to block another, while second is being blocked by the first. to get direction right you should write that part either like this

def sourceIssueId = newLinkedIssue.id
def destinationIssueId = it.id

or like this 

def sourceIssueId = it.id
def destinationIssueId = newLinkedIssue.id 

also if it won't work at all (red exclamation point on postfunction) please provide logs if there are any

MAG-II
Contributor
June 18, 2019

I appreciate the help. For some reason I am still not getting the correct results. When looking at the post function configuration it says that there have been "no failures in the last 5 executions," so no kinds of errors show up on the logs. 

When the create issue transition is triggered (with the script) nothing seems to happen. The newly created Issue does not get linked to the two existing linked Issues.

I tried using both parts:

def sourceIssueId = newLinkedIssue.id
def destinationIssueId = it.id

and

def sourceIssueId = it.id
def destinationIssueId = newLinkedIssue.id 

 

Not sure what the problem could be.

Ilya Turov
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 18, 2019

let's try logging to see if we are finding our issues:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
//here i assume you only have three linked issues, otherwise you need to find them
def linkedIssues = issueLinkManager.getLinkCollectionOverrideSecurity(issue).allIssues
def oldLinkedIssues = linkedIssues.findAll {
//here we somehow find those two. maybe by their type or project
it.issueType.name in ["Test1", "Test2"] || it.projectObject.key == "VTEST"
}
log.warn "${oldLinkedIssues*.key}"
def newLinkedIssue = linkedIssues.find {
//here again we need to somehow find that issue
it.issueType.name == "Test3"
}
log.warn "${newLinkedIssue.key}"
linkedIssues.each {
//practice here with swapping sourceid and destination id to make a proper link
def sourceIssueId = newLinkedIssue.id
def destinationIssueId = it.id
//find link type id you want from your system
def issueLinkTypeId = 10003
issueLinkManager.createIssueLink(sourceIssueId, destinationIssueId, issueLinkTypeId, 0L, currentUser)
}

i've added two log.warn lines, they should help us determine if we actually found the issues to link

MAG-II
Contributor
June 18, 2019

I added the above script and took a screenshot of the logs. Not exactly sure what I'm looking for, but this is what came up - 

 

LOGS.PNG

Ilya Turov
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 18, 2019

the line where it says "can't get property 'key' on null object is enough"

looks like it can't find the third issue

try moving this postfunction to the very end of postfunctions list

ps: I believe logs written by the postfunction should be found in it's info, dunno how better to explain it

MAG-II
Contributor
June 18, 2019

I really appreciate your patience and responsiveness. I moved the post function to the very bottom of the list with the original script you provided. I am getting errors, and I do see it in the logs. 

Maybe I have my data inputs to your script incorrect. For instance, when I type "Test3" into your script I am referring to the Issue Type that is being created. The same Issue Type that the post function script is being configured on. 

I apologize for all of the confusion. I will continue to test things out different ways.LOGS.2.PNG

Ilya Turov
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 18, 2019

though all that patience still isn't getting us anywhere

the errors still mean that it fails to find that third issue, meaning that somehow it's not linked to the main one at the moment we are executing the postfunction, that's my only guess. though i feel like it should

hard to debug remotely

Suggest an answer

Log in or Sign up to answer