How do I set Probability via a Dropdown List

In the cloud version, the system only allows you to set risk values via the slider control. Users may wish to set the values using a dropdown box. This is possible using script runner, as described below. Note that this is an advanced operation that is recommended only for experienced scripters.

The following script takes the value from a custom dropdown field called Probability Input which has been manually initialized with the probability values from your risk model (Very Unlikely, etc). The script should be attached to a Scriptrunner listening event for Issue Updated for the relevant projects.

Important: You will need to change the label map in step 2 below to reflect your risk model. Unfortunately, the label ids are not necessarily sequential (as you will see in the example below). The best way to determine the id is to use the Entity Property Tool and observe the changing id as you change the probability using the standard risk assessment panel.

import groovy.json.JsonSlurper
import groovy.json.JsonOutput

// 1. Grab issue key & changed fields
def ik          = issue.key
def changeItems = (changelog.items ?: []) as List<Map>
def change      = changeItems.find { it.field == 'Probability Input' }
if (!change) {
    println "▶️ Probability Input not changed—exiting"
    return
}

// 2. Map label → ID
def labelToId = [
  'Very Unlikely' : 5,
  'Unlikely'      : 3,
  'Likely'        : 2,
  'Very Likely'   : 1,
  'Almost Certain': 4
]
def newLabel = change['toString']
def newId    = labelToId[newLabel]
if (!newId) {
    println "⚠️ Unmapped Probability Input value: ${newLabel}"
    return
}
println "▶️ Mapped '${newLabel}' → ID ${newId}"

// 3. Fetch existing pbrr-assessment property
def propKey   = 'pbrr-assessment'
def getResult = get("/rest/api/2/issue/${ik}/properties/${propKey}").asString()
if (getResult.status != 200) {
    println "⚠️ pbrr-assessment property not found (HTTP ${getResult.status})—exiting"
    return
}

// 4. Parse and unwrap the inner payload
def wrapper = new JsonSlurper().parseText(getResult.body) as Map
def payload = (wrapper['value'] ?: [:]) as Map
println "▶️ Unwrapped payload: ${JsonOutput.toJson(payload)}"

// 5. Cast to Maps before accessing
def inherentBlock = payload['inherent'] as Map
if (!(inherentBlock instanceof Map)) {
    println "⚠️ No inherent block—exiting"
    return
}
def probabBlock = (inherentBlock['probab'] ?: [:]) as Map
if (!(probabBlock instanceof Map)) {
    println "⚠️ No inherent.probab block—exiting"
    return
}

// 6. Update only the probab.id and probab.name
probabBlock['id']   = newId
probabBlock['name'] = newLabel
println "▶️ Updated inherent.probab: ${JsonOutput.toJson(probabBlock)}"

// 7. Write back only the inner payload
def putResult = put("/rest/api/2/issue/${ik}/properties/${propKey}")
                     .header('Content-Type', 'application/json')
                     .body(JsonOutput.toJson(payload))
                     .asString()
println "▶️ PUT /properties/${propKey} returned HTTP ${putResult.status}"