Skip to main content
Book your demo
Example scripts
To homepage
Jira
Cloud icon
Cloud

Add options to custom field

Tags
Created 12 month(s) ago, Updated 4 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
groovy
import groovy.json.JsonOutput

def fieldId= "customfield_10083"  // Id of the custom field that needs new options
def contextId = "10193" // Context associated with the field

// List of option values to be added to the custom field
def optionValueList = ["1","2","3"]

// Payload with the options (for the POST request that will add them as field options)
optionValueList.each
        {
            def optionValue = it
            def optionPayload = [
                    options: [
                            [
                                    value: optionValue,
                                    disabled: false // Assuming the option should be enabled
                            ]
                    ]
            ]

// The POST request to add the option
def response = post("/rest/api/3/field/${fieldId}/context/${contextId}/option")
        .header("Content-Type", "application/json")
        .body(JsonOutput.toJson(optionPayload))
        .asString()
        }
Having an issue with this script?
Report it here