• 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

This widget could not be displayed.
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
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

214 views 1 3
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