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

Manjunatha K R January 12, 2017

 

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
Answer accepted
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 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