Scriptrunner: Groovy: getCustomFieldObject return ImmutableCustomField

Hi folks,

Need some help and I am stuck in this issue.

When I do ComponentAccessor.getCustomFieldManager().getCustomFieldObject I get back ImmutableCustomField with which I am not able to read or update the custom field value.

```

def customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10011")

log.info(cField.getClass())
String val = getCustomFieldValue(cField)

 

```

output when I run in console:
2017-11-21 11:47:52,415 INFO [acme.CreateSubtask]: class com.atlassian.jira.issue.fields.ImmutableCustomField

2017-11-21 11:47:52,418 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField) values: [Chargeback Status] at Script243.run(Script243.groovy:40)

1 answer

Ahh!! Figured it out myself.

 

Solution:  You need to have the reference to the issue always either in console or in post function. Only then it works and updates my CustomField.

I don't know behind scenes what is going on but when you do 

getCustomFieldValue(cField)    --> Ouputs the error above
issue.getCustomFieldValue(cField)   --->  Gets me the actual value

What led to this confusion in first place is I kept reading docs where people said there is no need to use "issue" if you are in post function as the scriptrunner already has context of the "issue" but apparently that isn't a sweet route for me.

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

85 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