Linking Issues in jira using groovy

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

This widget could not be displayed.

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();
	}

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

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);
	}

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

cool.. Glad to hear it worked!!!

Cheers..

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?

This widget could not be displayed.

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();

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?

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
This widget could not be displayed.

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);

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.

if you want to remove use the following code

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

issueLinkManager.removeIssueLink(issueLink , remoteuser);

Thanks,

Finally all done, Thanks a lot.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

536 views 23 15
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