Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Populate Tempo Dynamic Drop-down using a REST Endpoint

Created 1 year ago, Updated 2 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.0 - 8.6)
compatibility bullet
ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

tempoWorkType(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
    def callbackFn = queryParams.getFirst("callback")

    def options = [
        values: [
            [
                key  : "TRIAGE",
                value: "Triage"
            ],
            [
                key  : "DEV",
                value: "Development"
            ],
            [
                key  : "QA",
                value: "Quality Assurance"
            ]
        ]
    ]
    def jsObjectOptions = new JsonBuilder(options).toPrettyString()
    def resp = "${callbackFn} ( ${jsObjectOptions} )".toString()

    // Adding 'application/javascript' is needed to prevent a browser error like this: script cannot be executed due to
    // wrong MIME type.
    // For example, the error in Chrome is: "Refused to execute script from '*' because its MIME type
    // ('application/javascript') is not executable, and strict MIME type checking is enabled."
    Response.ok(resp)
        .header('Content-Type', 'application/javascript')
        .build()
}
Having an issue with this script?
Report it here