Script gods,
I have created a short script field that looks up values from an issue picker field to display to the user in forms and reports. This seems to work well enough except for issue creation where it's throwing a serializer error - although the issue is still properly created.
This is the script:
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//lookup the Feature Group value from the Feature issue then get the Feature Group issue object
def fgField = customFieldManager.getCustomFieldObjectByName("Feature Group")
def fgIssueKey = issue.getCustomFieldValue(fgField).toString()
def fgIssue = issueManager.getIssueObject(fgIssueKey)
//get the Context value from the Feature Group issue object
def context = customFieldManager.getCustomFieldObjectByName("Context")
def contextValue = fgIssue.getCustomFieldValue(context);
//return the value to the script field
return contextValue
this is the error:
Exception occurred: com.atlassian.plugins.rest.common.json.JsonMarshallingException: org.codehaus.jackson.map.JsonMappingException: No serializer found for class com.atlassian.jira.issue.customfields.option.LazyLoadedOption and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.atlassian.jira.quickedit.rest.api.field.QuickEditFields["createdIssueDetails"]->com.atlassian.jira.rest.v2.issue.IssueBean["fields"]->java.util.HashMap["customfield_17317"])
any help would be greatly appreciated!
Is your "Context" field a single select by any chance?
Is so, the contextValue is returned as "LazyLoadedOption".
So try to return like this:
return contextValue?.value
@Peter-Dave Sheehan that did the trick! thank you. I made a couple other updates to get rid of the static type errors and my final script looks like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//lookup the Feature Group value from the Feature issue then get the Feature Group Issue
def fgField = customFieldManager.getCustomFieldObjectByName("Feature Group")
def fgIssueKey = issue.getCustomFieldValue(fgField).toString()
def fgIssue = issueManager.getIssueObject(fgIssueKey)
//get the Context value from the Feature Group issue
def contextFld = customFieldManager.getCustomFieldObjectByName("Context")
def contextValue = getCustomFieldValue(contextFld) as LazyLoadedOption;
//retrun the value to the script field
return contextValue?.value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
alternative method/way but similar concept, broken down for simpler understanding
import com.atlassian.jira.component.ComponentAccessor
def modRating
//select list field below
def modVerRatingField = customFieldManager.getCustomFieldObjectsByName("Final Materiality Rating").first()
//modRating = focusIssue.getCustomFieldValue(modVerRatingField)?:0
//using above will throw the error. use below when calling the select list value field
modRating = (focusIssue.getCustomFieldValue(modVerRatingField)?.value)?:0
return modRating
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.