It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script to count linked (several) linked issuess, per type


We have a high level issue type called "Capability". That is the 'Parent of', via regular issue links the standard JIRA Epic issue type.

Inside epics, as issues in epics, we have stories and actions issue types. Stories and/or actions might have sub-tasks, or not (called 'Task').

When we transition a Capability to a certain status, we would like to add a comment to it that will write:

Number of Epics with a certain link in a URL field (http:\\test)

Number of stories 

Number of actions

Number of tasks (the tasks have a field called TaskType - select list) . It would be great to count per task type.

Would it be possible to achieve this via a Scriptrunner postfunction?

Any code is appreciated.


Thank you!

2 answers

Hi @Mihai Mihai ,

My script validator check if story has link to issue type 'test' and project 'PRKEY'.

if (issue.issueType?.name == 'Story'){

def hasT = false

def links = issueLinkManager.getOutwardLinks(issue.getId())
if (links.find{ (it.getDestinationObject().issueType?.name == 'TestCase') && (it.getDestinationObject().getProjectObject().getKey() == 'PRKEY') }){
hasT = true

if (hasT){
return true
return false




Yes, that is easy to do.

I'll give you some examples (counting stories/tasks in Epics and counting subtasks in issues). I guess you can extend this to your requirements ? (your link names, issue type names, ... add tests on custom field, ...)

Count Stories/tasks in Epics (assume you have an Epic in variable epicIssue) :

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()

Integer count = 0
issueLinkManager.getOutwardLinks(epicIssue.getId()).each {epicLink ->
if (epicLink.getIssueLinkType().getName() == "Epic-Story Link") {
Issue epicLinkedIssue = epicLink.getDestinationObject()
String liIssueType = epicLinkedIssue.getIssueType().getName()
if (liIssueType in ["Story", "Task"] {
count ++

 Count subtasks in issue:

Integer count = 0
issue.getSubTaskObjects().each { subIssue ->
String issueType = subIssue.getIssueType().getName()
if (issueType == "Sub-task") {
count ++

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you