This example show a button in the “More” option of the issue tickets called “Approve this issue“. This button call a Scriptrunner REST custom Endpoint and returns a “flag” Object to be shown as alert in the ticket.

Captura de pantalla 2017-03-29 a las 12.33.59

First go to “Add-ons-> Scriptrunner –> REST Endpoints” and add this script:


import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonOutput
import groovy.transform.BaseScript

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

@BaseScript CustomEndpointDelegate delegate

approve(httpMethod: "GET") { MultivaluedMap queryParams ->

// the details of getting and modifying the current issue are ommitted for brevity
def issueId = queryParams.getFirst("issueId") as String // use the issueId to retrieve this issue

def flag = [
type : 'success',
title: "Issue approved",
close: 'auto',
body : "This issue "+issueId+" has been approved for release"
]

Response.ok(JsonOutput.toJson(flag)).build()
}

Then save the REST Endpoint.

Once saved, you must create a new WebFragment.

Then go to “Add-ons –>Scriptrunner –> Script Fragments” and select the Built-in template “Custom WebItem

Fill the form with these values:

Captura de pantalla 2017-03-29 a las 12.39.56

Once saved, you can try the Option in some ticket and see the results:

Captura de pantalla 2017-03-29 a las 12.41.04

BTW you can try the REST Endpoint invoking this URL (you must be logged in JIRA through the browser to see the response):

https://{jira_url}/rest/scriptrunner/latest/custom/approve?issueId=XXXX

Captura de pantalla 2017-03-29 a las 12.42.11

NOTE: See here the list of possible locations for your WebItem

Posted by:e6967712

2 replies on “JIRA Scriptrunner REST Endpoint & Web Fragment example

    1. Hi Jan, yesterday I was trying this example with the last version of JIRA & Scriptrunner and works fine for me (and my class). Regards!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s