Linking Issues in jira using groovy

AKASHB July 24, 2013

Hi All,

I am trying hard to find the all the issue link types first, so i am using a method but its noe working, so can anybody help me out with this.

//method

Collection<IssueLinkType> issueLinkTypes= issueLinkTypeManager.getIssueLinkTypesByName()

now here the String parameter i am passing is Relates to but its still not taking, So any suggestions

I am getting error as

"The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.link.DefaultIssueLinkManager."

3 answers

1 accepted

3 votes
Answer accepted
RambanamP
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.
July 24, 2013

you are trying to print object so it will show like that only

itreate the linktypess collection as

for (IssueLinkType linktype : issueLinkTypes) {
		String name=linktype.getName();
		String id=linktype.getId();
	}

AKASHB July 24, 2013

Thanks , So my final code should be like this

Collection<IssueLinkType> issueLinkTypes1 = ((IssueLinkTypeManager) ComponentManager.getComponentInstanceOfType(IssueLinkTypeManager.class)).getIssueLinkType();
for (IssueLinkType linktype : issueLinkTypes) {
String name=linktype.getName();
String id=linktype.getId();
}
log.warn("Issue Link Types : " + IssueLinkType)

But when i check in log i am getting this output instead of names:

2013-07-25 14:00:10,988 http-8080-6 WARN addteq 840x26167x1 1dglm65 10.1.1.125 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.FinalTRMGroovy] Issue Link names : interface com.atlassian.jira.issue.link.IssueLinkType

RambanamP
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.
July 24, 2013

if you want to print linktype name then use this

for (IssueLinkType linktype : issueLinkTypes) {
		String name=linktype.getName();
		log.warn("Issue Link Type Name : " + name);
		String id=linktype.getId();
		log.warn("Issue Link Type Id : " + id);
	}

AKASHB July 24, 2013

Thanks a lot Rambanam.. I got it what i want. It worked for me.

RambanamP
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.
July 24, 2013

cool.. Glad to hear it worked!!!

Cheers..

AKASHB July 24, 2013

one last thing Rambanam:

I have two Mutable issues namely:

a) issue

b) opt

now after executing above code now i want to create a link between these two issue types, So how can it be possible.

I have figured out this way,


linkManager.createIssueLink(issue.getId(),opt.getId(),issueLinkTypes.getAt(1),1,currentUser)

but this show incompatility issues.

Any comments?

3 votes
RambanamP
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.
July 24, 2013

use following code to get link types

Collection&lt;IssueLinkType&gt; issueLinkTypes = ((IssueLinkTypeManager) ComponentManager
				.getComponentInstanceOfType(IssueLinkTypeManager.class)).getIssueLinkTypes();
		(or)		
	Collection&lt;IssueLinkType&gt; issueLinkTypes=ComponentAccessor.getComponentOfType(IssueLinkTypeManager.class).getIssueLinkTypes();

AKASHB July 24, 2013

but when i do log.warn, i am getting output at the log file as

Issue Link Types : [com.atlassian.jira.issue.link.IssueLinkTypeImpl@ffffffca, com.atlassian.jira.issue.link.IssueLinkTypeImpl@fffffe53, com.atlassian.jira.issue.link.IssueLinkTypeImpl@fe53fbd1]

So how can i get the name or ID?

Manjunatha K R January 12, 2017

Hi Rambanam Prasad,

I went through almost so many of the Atlassian Answers, which talks about mainly on "clone an issue and create issue links" since from 2 days. But the code posted here to create issue link helped me so quickly to create the needed Issue links in my workflow. So Really thank you very much for this Answer posted here.

But one clarification needed, by using the above code it's establishing by default "clones" (i,e Outward Description) and but I would like to create a issue link type of "is cloned by" (i,e Inward Description). Please suggest how to do this.

I am using the below script posted to clone issues and create Issue links in my workflow post function.

Issue Links:

clones

INT-1744 CLONE - Testing Auto clone issue latest-clone with linking on 13th Jan ENGINEERING SUPPORT 

INT-1745 CLONE - Testing Auto clone issue latest-clone with linking on 13th Jan ENGINEERING SUPPORT

 

selectedComponents?.each { LazyLoadedOption it -&gt;
    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&lt;String,Object&gt; newIssueParams = ["issue":newIssue] as Map&lt;String,Object&gt;
    issueManager.createIssueObject(currentUser, newIssueParams)
 
	IssueLinkManager linkManager = ComponentManager.getInstance().getIssueLinkManager()
        
    Collection&lt;IssueLinkType&gt; 	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
2 votes
RambanamP
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.
July 24, 2013

try with the following code

Collection&lt;IssueLinkType&gt; issueLinkTypes = ((IssueLinkTypeManager) ComponentManager
				.getComponentInstanceOfType(IssueLinkTypeManager.class)).getIssueLinkTypes();	
	String linkID=null;
	for (IssueLinkType linktype : issueLinkTypes) {
		String name=linktype.getName();
		if(name.equals("Clone")){// change link name here
			linkID=linktype.getId();
			break;
		}
	}
		
	linkManager.createIssueLink(issue.getId(), opt.getId(), Long.parseLong(linkID),Long.valueOf(0), currentUser);

AKASHB July 24, 2013

And if i have to delink then i should use the delete option rgt?

Man you are genius, I got all the thinks in right shoes now. Many Many thanks.

RambanamP
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.
July 24, 2013

if you want to remove use the following code

issueLink = issueLinkManager.getIssueLink(sourceId, destId, linkType);

issueLinkManager.removeIssueLink(issueLink , remoteuser);

Thanks,

AKASHB July 24, 2013

Finally all done, Thanks a lot.

Suggest an answer

Log in or Sign up to answer