Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Set linked issue


I want to set a linked issue with groovy post function.


My current code didn't work... why ? Thanks!

def newFeatureIssue = issueManager.getIssueObject(temp) // Epic issue key here
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def featureLink = customFieldManager.getCustomFieldObjectByName("Parent Feature")
featureLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(featureLink), newFeatureIssue),new DefaultIssueChangeHolder())
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

1 answer

1 accepted

0 votes
Answer accepted


if you want to set a link then your code should look like this;

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()
linkMgr.createIssueLink(11111, 22222, 33333, 1, currentUser)

You can find more details here:

Thanks @Alexey Matveev _Appfire_ ,

Do you know how can I take the issue link type of inward ? I find the id of the link but how can I refer to the inward specifically ?


Thank you!


Each link has the outward and inward descriptions. Do you mean that you want to know the id of the inward description? If so, you do not need it. 

When you create a link between issues using createIssueLink, the first variable is the source issue(outward) and the second variable is the destination issue (inward).

Thanks !! you right :) @Alexey Matveev _Appfire_

The only problem is that the link is added and not switch.. How can I delete the previous one ??

It would be something like this:

    def linkMgr = ComponentAccessor.getIssueLinkManager();
    def issueLink = linkMgr.getIssueLink(sourceIssue.getId(), destinationIssue.getId(), linkTypeID);
   if (issueLink != null) {
      linkMgr.removeIssueLink(issueLink, user);

The IssueLinkManager class is responsible for handling links. You can have a look at all available methods here: 

@Alexey Matveev _Appfire_ Put this code before or after the 




When I put it after, it deleted the link I just added, I need to delete the previous one. 

You should put it before the createIssueLink

@Alexey Matveev _Appfire_

Hi, I did it like this, and it worked in the console..

I copy it to post function.. not working, why is that ?



//remove the new feature
issueLinkManager.getInwardLinks( {IssueLink iLink ->
if(iLink.getLinkTypeId() == 10402){ //Feature Epic

Issue linkedIssue = iLink.sourceObject
issueLinkManager.removeIssueLink(iLink, user);
def userManager = ComponentAccessor.userManager
//Add the previous feature
issueLinkManager.createIssueLink(PrevFeature.getId() as Long,issue.getId() as Long, 10402L as Long, 1 as Long, user);
//ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);
catch (Exception e) {
throw e

Is this post function in the create issue tranistion? If so, is it last in the list of post functions? What are the errors? What does not work?

@Alexey Matveev _Appfire_ , It is a post function of 'change parent' , and I put it first inside epic workflow.

There are no error, the link didn't change.. I try to take the previous one, and switch the new one with the previous..


This is my full code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.version.Version
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean 
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import com.atlassian.jira.project.version.VersionManager 
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.config.IssueTypeManager;

IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)

//def issueManager = ComponentAccessor.getIssueManager();
//Issue issue = issueManager.getIssueObject("WBL-19638");
// your actions if the field has changed

//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
//Get temp with fix version
def tempVersion=fixVersions[0];

//Get Epic Link Key
def feature = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Feature");
def featureKey = issue.getCustomFieldValue(feature);
Issue featureIssue = issueManager.getIssueObject(featureKey.toString());
log.warn featureKey;

//Internal feature checkbox ?
def internal = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Internal Feature");
//return internal;
def selectedValues = internal.getValue(featureIssue);


//Get fix version of Epic
Collection<Version>fixVersionsFeature = new ArrayList<Version>();
def tempVersion2=fixVersionsFeature[0];
//If tempVersion == fixVersionsEpic
//if temp != fixVersionsEpic
//error message
UserMessageUtil.error("Failed. Fix version of Epic should be like the Feature's fix version");
//Get list and size of the previous versions
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
List<ChangeItemBean> changeList = changeHistoryManager.getChangeItemsForField(issue, "Parent Feature")
def size = changeList.size();
def temp= changeList[size-1].getFromString();
//Set the previous feature
Issue PrevFeature = issueManager.getIssueObject(temp.toString());
//Set the previous feature
def userManager = ComponentAccessor.userManager
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def issueLinkManager = ComponentAccessor.getIssueLinkManager();

//remove the new feature
issueLinkManager.getInwardLinks( {IssueLink iLink ->
if(iLink.getLinkTypeId() == 10402L){ //Feature Epic

Issue linkedIssue = iLink.sourceObject 
issueLinkManager.removeIssueLink(iLink, user);

//Add the previous feature
issueLinkManager.createIssueLink(PrevFeature.getId() as Long,issue.getId() as Long, 10402L as Long, 1 as Long, user); 
//ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);
catch (Exception e) {
throw e



Suggest an answer

Log in or Sign up to answer

Atlassian Community Events