Fetch field value from Epic and display this value in Story

 

Hi all,

I hope someone's able to help me here. What we're trying to do with the Scriptrunner add-on for JIRA is to fetch a specific field value and display this value in a scripted field. What we have so far is this:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

enableCache = { -> false }

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField EpicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
	def EpicValue = issue.getCustomFieldValue(EpicLink);

CustomField cField = customFieldManager.getCustomFieldObjectByName('SAP Project Number');
	def cFieldValue = EpicValue.getCustomFieldValue(cField);

 

Actually it works (the desired value get fetched and displayed at the right place) but in the catalina lo and also in scriptrunner it shows us an error saying:

 

[Static type checking] - Cannot find matching method

java.lang.Object#getCustomFieldValue

(com.atlassian.jira.issue.fields.CustomField). Please check if the declared type is right and if the method exists.

 

In the log I can see this:

2017-06-21 16:57:21,724 http-nio-8080-exec-24 ERROR bocadm 1017x29651x2 14z5dx 10.55.54.56,10.130.30.9 /rest/scriptrunner-jira/latest/scriptfields/12705/preview [c.o.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: AFP-20197, field: SAP Project Number from Epic
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField) values: [SAP Project Number]
Possible solutions: getCustomFieldValues(java.util.Map), getCustomFieldType()
at Script22.run(Script22.groovy:13)

 

Does anybody have a clue how to fix this?

 

Thanks and regards,

Cédric

 

1 answer

This widget could not be displayed.

Hello mate:

I believe you got an error in your last line:

It should be issue, and not EpicValue. Try this:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

enableCache = { -> false }

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField EpicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
 def EpicValue = issue.getCustomFieldValue(EpicLink);

CustomField cField = customFieldManager.getCustomFieldObjectByName('SAP Project Number');
 def cFieldValue = issue.getCustomFieldValue(cField);

Cheers!

DYelamos

Hi Dani,

Thanks but this doesn't help. I tried this already. The thing is we wan to fetch a specific field value from a parent/epic issue and display this value in a scripted field in a child/story issue.

Any ideas?

 

Regards,

Cédric

You can extend that code a bit to fetch a value from the epic.

Issue epicIssue = (Issue) EpicValue
					
if(epicIssue) {
epicFieldValue = epicIssue.getCustomFieldValue(cField);
}

 

Thanks Nic! This has fixed our problem.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

539 views 3 19
Read article

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