Scriptrunner: Groovy: getCustomFieldObject return ImmutableCustomField

venkatesh kara November 21, 2017

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

1 vote
venkatesh kara November 21, 2017

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
TAGS
AUG Leaders

Atlassian Community Events