Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Inward & Outward links in ScriptRunner script field?

Hello Atlassian community! I'm trying to create a Scripted Field that will sum up the value of a number field on all linked issues, however so far I can only get it to work in one direction or the other. I've found some threads about including both Inward and Outward links in other contexts, but I can't get them to work for a Scripted Field.

Has anyone set something like this up before, or have any insight? Here's the two versions of the scripts that work, one for each direction:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def linkedIssues = ComponentAccessor.issueLinkManager.getInwardLinks(
if (!linkedIssues) {
return null

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().sourceObject).findByName('Number Custom Field')
if (!customField) {
log.debug "Custom field is not configured for that context"
return null

linkedIssues*.sourceObject.sum { Issue it -> it.getCustomFieldValue(customField) ?: 0 }
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(
if (!linkedIssues) {
return null

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().destinationObject).findByName('Number Custom Field')
if (!customField) {
log.debug "Custom field is not configured for that context"
return null

linkedIssues*.destinationObject.sum { Issue it -> it.getCustomFieldValue(customField) ?: 0 }


1 answer

1 accepted


Could you try the following?


import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
def log = Logger.getLogger("com.nolddor") log.setLevel(Level.DEBUG) @PluginModule IssueLinkManager issueLinkManager
CustomFieldManager customFieldManager //-------------------------------------------------------------- // You must change the following variables as your needs //-------------------------------------------------------------- def numericFieldName = "Number Custom Field" //--------------------------------------------------------------
//Retrieve customfields from the system
def numericField = customFieldManager.getCustomFieldObjectsByName(numericFieldName).find()

// Ensure source fields really exist
// Look for all linked issues
def inwardLinkedIssues = issueLinkManager.getInwardLinks(*.sourceObject
def outwardLinkedIssues = issueLinkManager.getOutwardLinks(*.destinationObject

def linkedIssues = inwardLinkedIssues + outwardLinkedIssues

return linkedIssues.sum{ Issue linkedIssue -> linkedIssue.getCustomFieldValue(numericField) ?: 0 }




Hi Jack!

I'm getting a "could not find matching method" for getCustomFieldValue on line 34. Which seems weird, since everything being imported suggests that should be recognized, and it's used in my current version of the script. Any idea why it wouldn't be recognized here?

It was my fault, I forgot to cast the closure item into an Issue class.

I've edited my previous message, could you try again please?


No worries, I missed that as well! Thank you very much, that worked :D

@Jack Nolddor _Sweet Bananas_  This is exactly what I was looking for, it works great, I have an additional question, is it possible to add value from this task to the sum?

The same fields but from linked issues and this task?


Never mind, it was easy, just add ValA +

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