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

This widget could not be displayed.

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

This widget could not be displayed.
@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.

 

This widget could not be displayed.

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

This widget could not be displayed.

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

 

This widget could not be displayed.

@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
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

167 views 1 3
Join discussion

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