• 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 vote
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
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
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

91 views 0 1
Join discussion

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