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

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

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

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

 

## 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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 21, 2018 in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

1,243 views 10 18
Read article

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