GroovyScript that saves the number of links of a JIRA into a custom field

Lee Cash January 31, 2019

Hey everyone, 

I need to show (on a dashboard) the number of links a JIRA has. I've looked into plugins (like SnapMetrics) but I believe the best way is to write a Groovy Script that essentially calls issue in linkedIssues([issueid]) and then stores the result in a custom field of the issue. I can then display the custom field on the dashboard. 

My coding is rusty, however, and I was wondering if anyone could point me in the right direction as to how I would go about this? 

Thanks in advance, 

Lee 

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2019

Assuming you have Scriptrunner - create a new scripted field, with a number searcher, and set for a numeric output.

Then the script you need can be condensed down to one active line:

return issueLinkManager.getLinkCollectionOverrideSecurity(issue).size()

Lee Cash January 31, 2019

Many thanks Nic, 

Do I need to import a specific com.atlassian class? I ask because I am receiving an error stating: 

groovy.lang.MissingPropertyException: No such property: issueLinkManager for class: Script44 at Script44.run(Script44.groovy:2)

Thanks again, 

Lee

Lee Cash January 31, 2019

Just to mention that I experimented with adding the following: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager

def issueLinkManager = ComponentAccessor.getIssueLinkManager() 

I'm not getting the error: 

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.link.LinkCollectionImpl.size() is applicable for argument types: () values: [] Possible solutions: is(java.lang.Object), find(), sleep(long), find(groovy.lang.Closure), use([Ljava.lang.Object;), with(groovy.lang.Closure)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events