To learn more about Tempo products, please visit our Help Center. For support, see our Support Portal.
Dynamic work attribute based on the user selection
You can create a REST endpoint in Scriptrunner and select the endpoint url as a dynamic work attribute.
The sample script grabs the userkey from the person to log time against and populates a different option list depending on the user selected. Define the url for the dynamic worklog attribute as:
http://localhost:8080/rest/scriptrunner/latest/custom/tempoWorkType?user={author}
In runtime the {author}
part will be replaced with the Jira userkey of the person to log time for. The script below catches the user information passed from Tempo and populates a list based on the user.
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("JIRAUSER10000"):
options = [
values: [
[
key : "john",
value: "It is John"
]
]
]
break
case("JIRAUSER10128"):
options = [
values: [
[
key : "taylor",
value: "It is Taylor"
]
]
]
break
case("JIRAUSER10104"):
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()
}