Scriptrunner | Web-item | How to use custom variable in url of web-item?

Markus W_ BENES
Contributor
November 8, 2023

How can i get or how must i set the variables to be available in a web-item url or in a raw xml? (Jira server)

test.PNG


 

1 answer

1 accepted

1 vote
Answer accepted
Helmy Ibrahim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 2023

Hi @Markus W_ BENES,

This is currently not possible, and we do have a Feature Request raised for this: SRJIRA-2360

As a workaround, you can have the Web Item execute a Custom Rest Endpoint by providing its relative URL in the Link field. Then, you can do any custom scripting in the endpoint code and redirect the user to a dynamic URL, similar to the following example: Web Item (Redirect)

As an example, here is my Web Item configuration:

SS1.png

And here is my Rest Endpoint script:

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

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

import java.net.URLEncoder

@BaseScript CustomEndpointDelegate delegate

doSomething(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->

def myVariable = "Hello World"
def encodedString = URLEncoder.encode(myVariable)

Response.temporaryRedirect(URI.create("https://www.google.com/search?q=${encodedString}")).build()
}
Clicking on the Web Item will redirect me to a Google page with a searched query 'Hello World'.
I hope this helps!
Kind Regards,
Helmy
Markus W_ BENES
Contributor
November 10, 2023

Thank you for this piece of gold.

Suggest an answer

Log in or Sign up to answer