Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In runtime the {author} part will be replaced with the JIra Jira userkey of the person to log time for. The script below catches the user information passed from Tempo and populates a list depended based on the user.

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("john"):
        options = [
        values: [
            	[
                	key  : "john",
                	value: "It is John"
            	]
        	]
    	]
        break
        case("taylor"):
        options = [
        values: [
            	[
                	key  : "taylor",
                	value: "It is Taylor"
            	]
        	]
    	]
        break
        case("bob"):
        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()
}