Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner Groovy script to read all the 'Linked Epic Issues' for a Script Field

eXtensi Admin
Contributor
May 12, 2015

Hi,

Using Script runner I'd like to read all the 'Linked Epic Issues' from the epic object and create a script Field to be used on my card layout. Basically I want to display an epic with all the Linked Epic Issues on my board.

 

Reading normal links is pretty simple:

 

JiraAuthenticationContext authContext = ComponentManager.getInstance().getJiraAuthenticationContext();

IssueLinkManager issueLinkManager = ComponentManager.getInstance().getIssueLinkManager();

LinkCollection linkCollection = issueLinkManager.getLinkCollection(issue, authContext.getLoggedInUser());

Set<IssueLinkType> linkTypes = linkCollection.getLinkTypes();

return  linkCollection.getAllIssues().toString()

 

But how to read the Linked Epic Issues

 

 

CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager();

  CustomField cf = cfManager.getCustomFieldObjectByName('Linked Epic Issues');

  return cf.getGenericValue().toString()

 

returns

[GenericEntity:CustomField][id,10201][project,null][fieldtype,null][default,null][issuetype,null][customfieldsearcherkey,com.onresolve.jira.groovy.groovyrunner:textsearcher][description,null][name,Linked Epic Issues][customfieldtypekey,com.onresolve.jira.groovy.groovyrunner:scripted-field]

 

I can see that there is API EpicLinkManagerImpl

https://docs.atlassian.com/greenhopper/6.3.6.1/com/atlassian/greenhopper/manager/issuelink/EpicLinkManager.html#getIssuesInEpic%28com.atlassian.jira.issue.Issue%29

 

And even some examples

https://gist.github.com/ark09/c62a20c4cdae3f98df85

 

But

def epicLinkManagerImpl = getBean("epicLinkManagerImpl");

 

Returns

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getBean() is applicable for argument types: (java.lang.String) values: [epicLinkManagerImpl]

Possible solutions: getAt(java.lang.String), get(java.lang.String), getClass(), eval(java.lang.String)

A stacktrace has been logged

 

And when I try to import the EpicLinkManagerImpl I'm getting

 

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

Script65.groovy: 19: unable to resolve class com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl

 @ line 19, column 1.

   import com.atlassian.greenhopper.manager.issuelink.EpicLinkManagerImpl

 

So the package is not visible from the Script Runner at all.

So How do I access the instance of the EpicLinkManagerImpl then?

 

 

2 answers

1 accepted

2 votes
Answer accepted
KnudK June 29, 2015

Hi,

Strongly inspired by https://answers.atlassian.com/questions/263840 I got a list of issues with this script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.fugue.Option

if(issue.issueType.name=="Epic") {
    def epic = (Option)Option.option(issue)
    def epicLinkManagerImpl = getBean("epicLinkManagerImpl");
    issuesInEpic = epicLinkManagerImpl.getIssuesInEpic(issue)
    return issuesInEpic.toString()

}

return null

//Method to get the greenhopper bean instance
def getBean(String beanId)
{
    def ghPlugin         = ComponentAccessor.getPluginAccessor().getEnabledPlugin("com.pyxis.greenhopper.jira")
    def descriptor           = ghPlugin.getModuleDescriptor("greenhopper-launcher")
    def applicationContext     = descriptor.getModule().greenHopperCacheManager.applicationContext
    def beanInstance      = applicationContext.getBean(beanId)
    return beanInstance;
}
stevequintana
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 25, 2016

Wow!  I've been looking for a way to retrieve "Issues in Epic" for a long time - thanks Knud!

 

Yves Martin
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.
August 15, 2018

A pity Atlassian does not simply export EpicLinkManager service from OSGi plugin with @ExportAsService

0 votes
Nagaraju Reddy October 23, 2017 edited



Nagaraju Reddy October 30, 2017
## epic stories

#foreach($issue in $epicStory.getLinkedStories($xmlutils.escape($issue.key)))
<fo:table id="$xmlutils.escape($issue.key)" space-before="15mm" space-before.conditionality="discard">
<fo:table-body>
<fo:table-row>
<fo:table-cell number-columns-spanned="19">
<fo:block font-size="140%" font-weight="bold"> $xmlutils.escape($issue.summary)</fo:block>
<fo:block font-size="90%" color="#777777">
#if($issue.dueDate && $fieldVisibilityManager.isFieldVisible('duedate', $issue)) $i18n.getText("issue.field.due"): $userDateTimeFormatter.withDefaultZone().withStyle($dateTimeStyle.DATE).format($issue.dueDate) - #end
$i18n.getText("issue.field.created"): $userDateTimeFormatter.withStyle($dateTimeStyle.COMPLETE).format($issue.created) -
$i18n.getText("issue.field.updated"): $userDateTimeFormatter.withStyle($dateTimeStyle.COMPLETE).format($issue.updated)
#if($issue.resolutionDate && $fieldVisibilityManager.isFieldVisible('resolutiondate', $issue)) - $i18n.getText("issue.field.resolution.date"): $userDateTimeFormatter.withStyle($dateTimeStyle.COMPLETE).format($issue.resolutionDate) #end
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>

## standard fields

<fo:block space-before="3mm" border="thin solid #CCCCCC">
<fo:block padding="4px" start-indent="4px" end-indent="4px" background-color="#F5F5F5" font-weight="bold">
Description
</fo:block>
<fo:block padding="4px" start-indent="4px" end-indent="4px">
$pdfRenderer.asRendered($issue, "description", $issue.description)
</fo:block>
</fo:block>

## subtasks
#if(!$issue.subTaskObjects.empty)
<fo:block space-before="3mm" border="thin solid #CCCCCC">
<fo:block padding="4px" start-indent="4px" end-indent="4px" background-color="#F5F5F5" font-weight="bold">
Scope
</fo:block>

#foreach($subtask in $issue.subTaskObjects)

<fo:block padding="14px" start-indent="14px" end-indent="14px"> -
$pdfRenderer.asRendered($subtask, "summary", $subtask.summary)
</fo:block>

#end
</fo:block>
#end
#end

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian community, loom ai, atlassian loom ai, loom, atlassian ai, record recaps of meetings, meeting recaps, loom recaps, share meeting recaps,

Loom’s guide to great meetings 📹

Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.

Register today!
AUG Leaders

Atlassian Community Events