Scriptrunner: Create issuelinks with postfunctions

Hi,

can anyone provide a complete script to create links between the current issue and another one (provided in a custom field) using a scriptrunner post function?

I have tried 57843583 scripts, none of them work, and I can't figure out what the problem is. I am already using postfunctions to set the summary based on certain field values and that's working without any problems. 

 

1 answer

1 accepted

Hi Superuschi,

I created the following script in a post function that will get the value from a custom field (text) and link it to the current issue whenever the user performs the desired workflow transition.

import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("TextFieldA")
def issueKey = issue.getCustomFieldValue(customField) as String

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueToLink = issueManager.getIssueObject(issueKey)

issueLinkManager.createIssueLink(issue.id, issueToLink.id, 10000, 1, user)

createIssueLink is doing all of the work here, with the following parameters:

  • issue.id - ID of the source issue
  • issueToLink.id - ID of the issue you want to link
  • 10000 - ID of the Issue Link Type (e.g., "duplicates")
  • 1 - sequence in which the order will appear on the UI
  • user - application user needed to perform the transaction

Simply change the parameters to the ones that fit your need.

Ohh thank you very much. Works as intended :-)

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 Jul 10, 2018 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...

183 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