behavior_copy object in single-select field onto global Numeric field

PHOTO EMBED

Tue Feb 11 2025 13:44:50 GMT+0000 (Coordinated Universal Time)

Saved by @belleJar #groovy

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours

//copy object in single-select field onto global Numeric field

def formField = getFieldById(getFieldChanged()) // "Estimated Story Points" field
def storyPointsField = getFieldByName("Story Points") // Numeric Field

def estimatedStoryPointsValue = formField.getValue()

if (estimatedStoryPointsValue) {
    try {
        // Convert the selected option into a numeric value
        def numericValue = estimatedStoryPointsValue.toString().toInteger()
        storyPointsField.setFormValue(numericValue)
    } catch (Exception e) {
        storyPointsField.setError("Invalid selection: Unable to convert to a number.")
    }
} else {
    storyPointsField.setFormValue(null) // Clear if no value selected
}
content_copyCOPY

jira behaviors