Script Field throwing Marshalling Exception on Issue Creation

John Hastings-Kimball
Contributor
May 19, 2020

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!

 

2 answers

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2020

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

John Hastings-Kimball
Contributor
May 26, 2020

@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
Like Azfar Masut likes this
0 votes
Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 31, 2023

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events