Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Custom Field value from linked Issue or EPIC through script runner

Smita Sinha March 22, 2018

Hi,

I would like to read custom field value from a linked EPIC. Once I am able to read the custom field value from EPIC/parent, I would like to set up this value to sub-task' custom field. I tried multiple forums but didn't help much.

I saw threads for reading custom field value, I am able to read custom field value from the issue I am in. However, a read from parent or epic is returning a null all times.

Thanks,

Smita

 

1 answer

0 votes
Alexey Matveev
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.
March 22, 2018

Could you provide your script?

Smita Sinha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 2, 2018

Hi Alex,

I have this code which is reading value from linked EPIC and custom field value from its own custom field. However I am very new to scripting and I am not sure how can I make it read custom field value from a linked issue or EPIC. I tried few scripts and removed them when they didn't work.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.CustomFieldManager

String testlinkType = ["IT Parent"]
String testlinkStatus = ["child of"]

def output =""


IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager()
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager();

output+="issue key: " + issue.key +"<br></br>"

for(IssueLink link in linkMgr.getInwardLinks(issue.id))
{
 
output+="linked issue type: " + link.issueLinkType.name+"<br></br>"
    output+="linked issue key: " + link.getSourceObject().getKey()+"<br></br>"
   output+="linked issue status (name): " + link.getSourceObject().getStatus().getName()+"<br></br>"
    output+="linked issue status (id): " + link.getSourceObject().getStatus().getId()+"<br></br>"
   // output+=link
   CustomField customField = cfManager.getCustomFieldObjectByName("Work Category");
   def customFieldValue = customField.getValue(issue)
   output+="My work category" + customFieldValue +"<br></br>"
   
//def customField = cfManager.getCustomFieldObject("Work Category")
    //   def childCfValue =link.getCustomFieldValue(customField)
}

Alexey Matveev
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.
April 2, 2018

Your script would look like this

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.FileSystemAttachmentDirectoryAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.link.IssueLink

def linkTypeList = ["Epic-Story Link"]

IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager()
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager();
def customField = cfManager.getCustomFieldObjectByName("custom field name")

for(IssueLink link in linkMgr.getInwardLinks(issue.id))
{
if ( link.issueLinkType.name in linkTypeList) {
log.error(link.getSourceObject().getCustomFieldValue(customField))
}
}

Suggest an answer

Log in or Sign up to answer