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

How to retrieve linked issue custom field values to parent issue.

Ash
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.
August 28, 2017

Hi All,

 

Is there any way I can pull linked issue values to parent issue.

For example, A is a parent issue and B is linked to A. Is there any way we can retrieve Issue B custom field values in Issue A. 

 

TIA!!

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ash
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.
August 28, 2017

Below is the code I'm using 

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("username").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_xxxx")
def linkedIssue = linkCollection.allIssues.first()
return linkedIssue.getCustomFieldValue(customField)
}

 

I get the error at the underlined code.

Joshua Yamdogo @ 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.
September 7, 2017

Hi Ashish,

Were you able to figure it out or do you still need help with this issue?

Josh

Ash
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.
September 7, 2017

Hi Joshua,

Can you please help me on this.

 

Thanks,
Ash.

Joshua Yamdogo @ 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.
September 11, 2017

Hi Ash,

You could create a scripted field that gets values from issues  that are linked. For example, if Parent issue A was of type "Bug", the code for your scripted field would look like this:

import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
if (issue.issueType.name == "Bug") {
issueLinkManager.getOutwardLinks(issue.id).first() { issueLink -> // go through all issues linked off of the Story
def linkedIssue = issueLink.getDestinationObject()
def customField = customFieldManager.getCustomFieldObjectByName("customfield_xxxx")
return linkedIssue.getCustomFieldValue(customField)
}
}
Ash
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.
September 19, 2017

Hi Joshua,

 

Thanks for your code, I see cannot find matching method error at line 5 as shown

 

linked script.jpg

Joshua Yamdogo @ 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.
September 21, 2017


Hi Ash,

Sorry about that, that script contained a small error.

However, I think that script will not work for you anyway. Could you clarify the relationship between Issue A and Issue B? Is this correct:

  • Issue A is the parent issue
  • Issue B is a sub-task of Issue A

In that case, a script like this should work:

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def subTasks = issue.getSubTaskObjects()
def childCfValue
if (subTasks) {
issue.getSubTaskObjects().each { subtask -> // go through sub-task issues
def customField = customFieldManager.getCustomFieldObject("customfield_12220")
childCfValue = subtask.getCustomFieldValue(customField)
}
}
return childCfValue
Ash
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.
September 21, 2017

Issue A is a Parent issue and Issue B is a linked issue to the parent issues.

 

Thank you,  I will try this code and update you.

Xoom Atlassian Administrator July 11, 2018

Hi Joshua

 

Can I get the script for linked issues? I am trying to get it for a linked issue which should have a custom text field filled. If it is empty, my validator should through error. 

Above script is working for subtasks. I tried to change it for linked issues but in vain, the linked issues script is not working, throwing error as shown in above screenshot of Ash

-Sumedh 

TAGS
AUG Leaders

Atlassian Community Events