Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Execute method when jira recive a GET RESPONSE with parameters

Stefano Rosario Aruta
Contributor
February 14, 2019

Hi i need help i need to make a script. I do not have i ide where i make this script.

i need that when i open this link:

http://localhost:8080/rest/scriptrunner/latest/custom/doSomething?issueId=10404&username=User13

i want that jira run a script where it execute a transition. Someone can help me?
 i make this script as ScriptRunner Rest Endpoint but it does not work:

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
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
//import com.atlassian.jira.user.util

@BaseScript CustomEndpointDelegate delegate

doSomething(httpMethod: "GET", groups: ["jira-administrators"]) {
MultivaluedMap queryParams, String body ->
def issueId = queryParams.getFirst("issueId") as String;
def userString = queryParams.getFirst("username") as String;
def issueGet = get('/rest/api/2/issue/' + issueId);
def issueService = ComponentAccessor.getIssueService();
//def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def user = ApplicationUser.getUser(userString);
def issueInputParameters = issueService.newIssueInputParameters();
def transitionValidationResult = issueService.validateTransition(user, issueGet.getId(), 11 as Integer, issueInputParameters);

if (transitionValidationResult?.isValid()) {
issueService.transition(user, transitionValidationResult);
return Response.ok(new JsonBuilder([Risoluzione: "Riuscito"]).toString()).build();
} else return Response.ok(new JsonBuilder([Risoluzione: "Fallito"]).toString()).build();
}

 

1 answer

0 votes
Marc Minten _EVS_
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.
February 15, 2019

Hi, what do you mean with "it does not work" do you get error messages ? Do you see errors in the Jira log files ?

Stefano Rosario Aruta
Contributor
February 15, 2019

Immagine.png

Marc Minten _EVS_
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.
February 15, 2019

These are just static type checks. You can ignore them.

Groovy does run time type checking, and this will run correctly.

If you would get rid of these errors, you should declere your variables with the corerct type:

ApplicationUser user = ...
Stefano Rosario Aruta
Contributor
February 15, 2019

can you make a code override?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events