Display contents of a field of issue A IN the linked issue B through Script Runner's Script Fields?

Hi,

Currently we're trying to expand the usability of "Linked Issues" throught the "Script Fields" feature of the add-on Script Runner:

We’d like to display contents of a custom or basic field of issue A IN the linked issue B (Link: A “connects with” B).

Is it actually possible to display information of a linked issue? And does anyone has a solution like f.i. a working script for a Script Field?

Robert

5 answers

1 accepted

Hi Robert,

I've drafted the following script so you can get some insight of how to retrieve the value of a custom field of a linked issue:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

def Issue issue = issue

def User user = ComponentAccessor.getUserManager().getUserByName("admin").getDirectoryUser()
def issueLinkManager = ComponentAccessor.issueLinkManager

def linkCollection = issueLinkManager.getLinkCollection(issue, user)

if (linkCollection && linkCollection.allIssues) {
    def CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
    def customField = customFieldManager.getCustomFieldObject("customfield_10800")
    def linkedIssue = linkCollection.allIssues.first()
    return linkedIssue.getCustomFieldValue(customField)
}

Hope it helps

Tks a lot With of addition of this code-frag, it worked great for me : below the import add this: String getSqlFeedValue(value){ String returnValue if (value?.class?.name == 'com.valiantys.jira.plugins.sql.customfield.SQLFeedContent'){ def values = value.getValues() returnValue = (values.size() > 0)?values[0]:null } else { returnValue = value } return returnValue } then change the last line to return getSqlFeedValue(linkedIssue.getCustomFieldValue(customField))

@Alejo Villarrubia [Adaptavist]'s answer is correct but will get the first issue that is linked in either direction. You probably want to follow one particular link type, in which case you could use:

 

for (IssueLink issueLink : issueLinkManager.getOutwardLinks(issue.getId())) {
    if (issueLink.getIssueLinkType().name == "Blocks") {
        return issueLink.destinationObject.getCustomFieldValue(...)
    }
}

For inward links, use getInwardLinks and sourceObject.

 

Thanks so far, Joao!

I already worked through the mentioned documentation. But since I'm not very experienced with Script Runner either, I couldn't figure it out. Also the described examples and their scripts are not helpful for what I need.

I'll try to work at your script base in the morrow.

Anybody else with some good advice or a working script?

Robert

0 votes

Hey Robert!

I made a script for something like this a couple of weeks ago, but I was working with sub-tasks and, as far as I went with it, I couldn't find a reliable way to do that for linked issues.

However, the script is below. Use it as a base for you to get started. I don't have much experience with Script Runner, so maybe taking some time to read its documentation (especially the one on Scripted Fields) you can achieve what you want.

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_id")
def cfValue = issue.parentObject.getCustomFieldValue(customField).toString()

if (cfValue != null) {
	return cfValue
}

information The "customfield_id" can be seen at your settings page for Field Configurations. Just hover the mouse over the Edit option that appears under the "Gear" icon on the right side of the field. See below:

image2015-2-18 12:22:34.png

Cheers!

Joao

 

@Alejo Villarrubia [Adaptavist] & @Jamie Echlin [Adaptavist]: Thanks for your help.

Due to changed priorities I unfortunately won't be able to try it in the next days.

After implementation I'll give some feedback.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,911 views 19 22
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