Include Page |
---|
| Tempo for Server and Data Center Header |
---|
| Tempo for Server and Data Center Header |
---|
|
You can create a REST endpoint in Scriptrunner and select the endpoint url as a dynamic work attribute.
...
Code Block |
---|
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 userkey = queryParams.getFirst("user")
def options = [
values: [
[
key : "none",
value: "No user did match the search"
]
]
]
switch (userkey)
{
case("johnJIRAUSER10000"):
options = [
values: [
[
key : "john",
value: "It is John"
]
]
]
break
case("taylorJIRAUSER10128"):
options = [
values: [
[
key : "taylor",
value: "It is Taylor"
]
]
]
break
case("bobJIRAUSER10104"):
options = [
values: [
[
key : "bob",
value: "It is Bob"
]
]
]
break
}
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()
} |