Programmatically obtain Epic Colour

Michał Ezman May 15, 2020

Hello, 
I'm trying, using ScriptRunner, programmatically obtain value from Epic Colour customField, but I'm failing miserably

 

I've tried using

Issue epic; //100% sure this issue is an Epic and has selected Epic Colour
CustomField cf_epicColour; //100% sure Epic Colour cf

epic.getCustomFieldValue(cf_epicColour); //Returns null
cf_epicColour.getValue(epic); //Also returns null

 

And nulls every time when I do so. (when at the same time, I can clearly see this values are set - either chcecking it via REST API or searching with visible Epic Colour column)

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"10001","self":"http://localhost:2990/jira/rest/api/2/issue/10001","key":"DEV-2","fields":{"customfield_10004":"ghx-label-3"}}

 

 

Unfortunately I can not use REST APi call, that's why I want to get this field value via CustomField class or any diffrent class avalaible (https://docs.atlassian.com/software/jira/docs/api/7.13.1/index.html?)

 

Does anyone has any ideas how to get this value?

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 24, 2020

When in doubt, simplify... can you run the following script in your Scriptrunner console?

import com.atlassian.jira.component.ComponentAccessor
def epicKey = 'JSP-1661'
def epic = ComponentAccessor.issueManager.getIssueObject(epicKey )
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName('Epic Colour') //12208
if(!epic){
return "Epic not found"
}
if(!cf){
return "Epic Colour not found"
} else {
log.info "Epic cf found: id=$cf.id"
}
epic.getCustomFieldValue(cf)

 If you don't get a value like "ghx-label-n", then what's in the log?

Michał Ezman May 25, 2020

To be honest I don't really know why it didn't work for me before...

But, it works now with your method (which isn't really that different from mine)

 

Thank you very much kind sir ;)

Suggest an answer

Log in or Sign up to answer