Jython: getCustomFieldValue returning com.atlassian.jira.issue.customfields.option.LazyLoadedOption

d August 29, 2012

We are upgrading from 4.2 to 4.4.5, so I am testing our Jython scripts. One is a post hook that sends an email about the issue. It looks something like this:

# Get access to custom fields
from java.util import Locale
from com.atlassian.jira import ComponentManager
from com.atlassian.jira.issue import CustomFieldManager
from com.atlassian.jira.issue.fields import CustomField
cfm = ComponentManager.getInstance().getCustomFieldManager()

# . . .

environment = issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_10321"))
product = issue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Product"))

# . . .

body += 'Environment and Product: ' + environment + '-' + product + '\r\n\r\n'

The error that I get is:

root cause: Traceback (most recent call last): File "/data/jira_home/jss/jython/workflow/send_announce.py", line 60, in <module> body += product + '\r\n\r\n' TypeError: unsupported operand type(s) for +: 'com.atlassian.jira.issue.customfields.option.LazyLoadedOption' and 'str'

I've been poking through API documentation but I can not understand why getCustomFieldValue is returning this object of type com.atlassian.jira.issue.customfields.option.LazyLoadedOption. Any ideas?

Thanks,

-danny

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
tier-0 grump
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 29, 2012

Danny

getCustomFieldValue returns any old objevct depending on the custom field. Your custom field must be a MultipleCustomFieldType (which is the base type for all the cascading selects and multiple selects. When you call getCustomFieldValue on one of these types it returns the Options, rather than the values, simply call getValue on the returned LazyLoadedOption to get the value from it.

Cheers

d October 29, 2012

So ... this code worked:

environment = issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_10321")).getValue()
product = issue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Product")).getValue()

TAGS
AUG Leaders

Atlassian Community Events