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
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))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for (IssueLink issueLink : issueLinkManager.getOutwardLinks(issue.getId())) { if (issueLink.getIssueLinkType().name == "Blocks") { return issueLink.destinationObject.getCustomFieldValue(...) } }
For inward links, use getInwardLinks and sourceObject.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 }
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.