My script to return the number of cloned issues not working as expected. it always returns 1.
Anyone know what the error might be? Also if I need to display the number of links that 'depend on' another link what do I replace the 'Cloners' with?
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.IssueLinkType import com.atlassian.jira.issue.link.IssueLinkTypeManager ComponentAccessor componentAccessor= ComponentAccessor.newInstance() Collection<IssueLinkType> issueLinkTypes=componentAccessor.getComponentOfType(IssueLinkTypeManager.class).getIssueLinkTypes(); count = 0; for (IssueLinkType linktype : issueLinkTypes) { String name=linktype.getName(); if(name.equals("Cloners")){ count++; } } return count;
Hi, Thanks a lot. Finally got it working. :)
I was running it as a scripted field. I was messing up the Outward and Inward Links. I got it to work for 'depends on' like this:
import com.atlassian.jira.component.ComponentAccessor def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueLinks = issueLinkManager.getOutwardLinks(issue.id) def subElements = issueLinks.findAll { it.getIssueLinkType().getName() == "Dependency" } return subElements.size()
I get the error
groovy.lang.MissingPropertyException: No such property: issue for class: Script5
at Script5.run(Script5.groovy:4)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.issue.Issue import org.apache.log4j.Category import com.atlassian.jira.component.ComponentAccessor def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueLinks = issueLinkManager.getOutwardLinks(issue.id) def subElements = issueLinks.findAll { it.getIssueLinkType().getName() == "Cloners" } subElements.size()
if you need to look for different link types just change the filter in the findAll closure to some other names (you can find them in Administration > System > Issue Features > Issue Linking).
For 'depends on' it would be probably
def subElements = issueLinks.findAll { it.getIssueLinkType().getName() == "depends on" }
Best regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you run your code in a post function, custom JQL function, scripted field or what is the context? It may be that issue.id is null in your case.
You may look for InwardLinks, try this
def issueLinks = issueLinkManager.getInwardLinks(issue.id)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Thanks for the help.
I tried to run the code for "Cloners", but Im getting 0 as the output for both number of issueLinks and and subElements.
size
().
Do you know what might mbe the issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
to get the issue link id's bi-directionally as follows
to get OUward links List<IssueLink> allOutIssueLink = issueLinkManager.getOutwardLinks(sourceIssue.getId()); for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) { IssueLink issueLink = (IssueLink) outIterator.next(); System.out.println(issueLink.getIssueLinkType().getId()); }
same way to get inword issueLink's
List<IssueLink> allInIssueLink = issueLinkManager.getInwardLinks(sourceIssue.getId()); for (Iterator<IssueLink> inIterator = allInIssueLink.iterator(); inIterator.hasNext();) { IssueLink issueLink = (IssueLink) inIterator.next(); System.out.println(issueLink.getIssueLinkType().getId()); if (issueLink.getIssueLinkType().getId() == 10) { Issue destinationIssue = issueLink.getDestinationObject(); } }
check this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Thanks for your ans.
I tried to run the code but Im getting this error:
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issueLinkManager for class: Script21
Do you know what might be the issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you have to get issuelinkmanager as follows
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Yes I need to get the number of cloned issues. (by counting the number of cloned issue links).
Do you how I could edit my code to achieve that ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Your script displays just the link types configured in the system. Thats why it is always 1.
But I suppose that you would like to display the number of clone issues connected to a given issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.