• Community
  • Products
  • Jira
  • Questions
  • how to set Issue Links direction to Inward for a specific Link Type(i,e Cloners) created using createIssueLink() using Groovy script

how to set Issue Links direction to Inward for a specific Link Type(i,e Cloners) created using createIssueLink() using Groovy script

 

how to set Issue Links direction to Inward for a specific Link Type(i,e Cloners) created using createIssueLink().

The below is my groovy script code, where I am cloning issues and creating Issue links from parent JIRA issue (i,e from which I have cloned the issues) to Cloned Issues.

But it's creating "clones" outward direction link from parent issue to cloned issues. But I would like to create "is cloned by" Inward direction link from parent issue to cloned issues. Please suggest how to achieve this.

selectedComponents?.each { LazyLoadedOption it ->
    def issueFactory = ComponentAccessor.getIssueFactory()
    def issueManager = ComponentAccessor.getIssueManager()
    def newIssue = issueFactory.cloneIssue(issue)
 
    newIssue.setSummary("CLONE - $issue.summary")
    newIssue.setProjectId(issue.projectId)
    newIssue.setDescription(issue.description)
    newIssue.setAssigneeId("Unassigned")
 
    Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
    issueManager.createIssueObject(currentUser, newIssueParams)
 
    IssueLinkManager linkManager = ComponentManager.getInstance().getIssueLinkManager()
         
    Collection<IssueLinkType>     issueLinkTypes1=ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class).getIssueLinkTypes();
    String linkID=null;
    for (IssueLinkType linktype : issueLinkTypes1) {
        String name=linktype.getName();
        log.warn("Issue Link Type Name : " + name);
        String id=linktype.getId();
        log.warn("Issue Link Type Id : " + id);
         
        if(name.equals("Cloners")){// change link name here
            linkID=linktype.getId();
            break;
        }
    }//for end
    log.warn("Issue Link Types : " + IssueLinkType)
    linkManager.createIssueLink(issue.getId(), newIssue.getId(),        Long.parseLong(linkID),Long.valueOf(0), currentUser);
 
}//each end

1 answer

1 accepted

0 votes
Accepted answer
Vasiliy Zverev Community Champion Jan 13, 2017

You should to change 2 first params for linkManager.createIssueLink(source, destination, ... )

Here is updated code

selectedComponents?.each { LazyLoadedOption it ->
    def issueFactory = ComponentAccessor.getIssueFactory()
    def issueManager = ComponentAccessor.getIssueManager()
    def newIssue = issueFactory.cloneIssue(issue)

    newIssue.setSummary("CLONE - $issue.summary")
    newIssue.setProjectId(issue.projectId)
    newIssue.setDescription(issue.description)
    newIssue.setAssigneeId("Unassigned")

    Map<String,Object> newIssueParams = ["issue":newIssue] as Map<String,Object>
    issueManager.createIssueObject(currentUser, newIssueParams)

    IssueLinkManager linkManager = ComponentManager.getInstance().getIssueLinkManager()

    Collection<IssueLinkType>     issueLinkTypes1=ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class).getIssueLinkTypes();
    String linkID=null;
    for (IssueLinkType linktype : issueLinkTypes1) {
        String name=linktype.getName();
        log.warn("Issue Link Type Name : " + name);
        String id=linktype.getId();
        log.warn("Issue Link Type Id : " + id);

        if(name.equals("Cloners")){// change link name here
            linkID=linktype.getId();
            break;
        }
    }//for end
    log.warn("Issue Link Types : " + IssueLinkType)
    linkManager.createIssueLink( newIssue.getId(), issue.getId(),   Long.parseLong(linkID),Long.valueOf(0), currentUser);

}//each end

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,647 views 18 21
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