Method to create a inward or outward link in script runner

Nallusamy Narayanaswamy June 11, 2021

There is a method to create a link in script runner. 

Is there a method or way to create  Inward or Outward link explicitly ?  As the inward or outward link name only will be visible to the users (not link name) , we want to create inward or outward link using script. 

 

 

2 answers

2 accepted

2 votes
Answer accepted
Payne
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 11, 2021

Create a variable of type com.atlassian.jira.issue.link.IssueLinkManager and then use the createIssueLink() method

The order of the issue IDs you pass as the first 2 arguments dictates the direction.

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 15, 2021

Hi @Nallusamy Narayanaswamy,

If you are using a listener or post-function, as @Payne mentioned, you could use the IssueLinkManager to create the issue link.

Below is a sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue

def customFieldManager = ComponentAccessor.customFieldManager
def issueLinkManager = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def customVersion = customFieldManager.getCustomFieldObjectsByName("Linked Project Versions")[0]
def customVersionValue = issue.getCustomFieldValue(customVersion).toString() as List<String>

def issueIds = issueManager.getIssueIdsForProject(11900)
def issues = issueManager.getIssueObjects(issueIds)

issues.each { sourceIssue ->

def versions = sourceIssue.fixVersions

versions.findAll {version ->
if(version.name in customVersionValue) {
issueLinkManager.createIssueLink(issue.id, sourceIssue.id, 10003, 1, loggedInUser)
}
}
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

You will also need to refer to the Issue Linking page as shown below issue_linking.png

and move your mouse over the Edit link to get the correct link id to be used as shown in the image below:-

issue_linking2.png

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer