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
Community moderators have prevented the ability to post new answers.
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
So ... this code worked:
environment = issue.getCustomFieldValue(cfm.getCustomFieldObject("customfield_10321")).getValue() product = issue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Product")).getValue()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.