Hi,
I am using Jira Software version 8.6 with Scriprunner.
Trying to write a listener that reads a single select list custom field and copies it to a number custom field of an issue.
I am getting the following error:
Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '13' with class 'com.atlassian.jira.issue.customfields.option.LazyLoadedOption' to class 'java.lang.Double'
I am using the following code:
"New Story Points" - Single Select list
"Story Points" - Number field
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def newStoryPointsChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "New Story Points"}
if (newStoryPointsChanged){
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def targetField = customFieldManager.getCustomFieldObjectByName("Story Points")
def sourceField = customFieldManager.getCustomFieldObjectByName("New Story Points")
def sourceFieldValue = (Double) event.issue.getCustomFieldValue(sourceField)
def targetFieldValue = event.issue.getCustomFieldValue(targetField)
targetField.updateValue(null, event.issue, new ModifiedValue(targetFieldValue, sourceFieldValue),new DefaultIssueChangeHolder())
}
Can you suggest the correct way for the following line:
targetField.updateValue(null, event.issue, new ModifiedValue(targetFieldValue, sourceFieldValue),new DefaultIssueChangeHolder())
Thanks,
Rupa
Select lists hold an "option" object, not a number, so your (Double) cast is nonsense. It's a like asking something like "what number is my penguin?".
My guess is that your "New Story Points" holds options with names that are displayed to the user like "one, two, three..." or "1, 2, 3...". You'll need to convert those labels into numbers. So
def sourceFieldValueName = event.issue.getCustomFieldValue(sourceField)
def saveValue = 0
if ("one".equals(sourceFieldValueName) ) {saveValue = 1}
if ("two".equals(sourceFieldValueName) ) {saveValue = 2}
or perhaps use "parseInt" to convert the name string to a number
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.