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

Deleted user February 18, 2015

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

2 votes
Answer accepted
Alejo Villarrubia [Adaptavist]
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.
February 18, 2015

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

DACHCOM CustomerCare August 24, 2015

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))

3 votes
JamieA
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.
February 18, 2015
@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.

 

1 vote
Deleted user February 18, 2015

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
Deleted user February 18, 2015

@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.

0 votes
João Palharini
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 18, 2015

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

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events