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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

78 views 0 5
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