Can't get value custom field value

Hello,

I have two lines script based on examples:

def pain = getCustomFieldValue("Pain if not delivered")
def gain = getCustomFieldValue("Gain if delivered")

which returns me an error:

Script function failed on issue: TP-1, actionId: 11, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Pain if not delivered]
    at Script21.run(Script21.groovy:1)

How can I solve that?

1 answer

0 vote

I'm not sure where you've got the examples from, but I doubt they say getCustomFieldValue(<string>)

You need to pass those calls a customfield object, not a random string - it doesn't know what to do with strings.  For example:

def cf = customFieldManager.getCustomFieldObject ("Gain if delivered")

def gain = getCustomFieldValue(cf)

(My notes actually say issue.getCustomFieldValue, but I've got a feeling groovy may not need it if you're in a post-function as it assumes you mean "current issue")

I tried another way:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
def painFieldId = "customfield_11401";
def gainFieldId = "customfield_11402";
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def gainCustomField = customFieldManager.getCustomFieldObject(gainFieldId);
def painCustomField = customFieldManager.getCustomFieldObject(painFieldId);

Now I'm reaching: No signature of method: com.atlassian.jira.ComponentManager.getCustomFieldManager() is applicable for argument types: () values: []

Hi - you should use "ComponentAccessor" to get JIRA managed component according to the latest document:

 
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()

please check the doc for more detail: https://docs.atlassian.com/jira/latest/com/atlassian/jira/component/ComponentAccessor.html

The suggestion is based on this link: https://docs.atlassian.com/jira/latest/com/atlassian/jira/ComponentManager.html

 

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...

321 views 0 6
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