Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,978
Community Members
 
Community Events
168
Community Groups

Call a transition by rest endpoint

Hello,

I wrote a script in 'REST Endpoint' and 'script fragments' that calls a transition by clicking a button.

The screen of this transition didn't pop-up but the transition itself happened.

I need this screen to shown before the transition, Can you know what is missing?

 

This is my 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 com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.Response
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import javax.servlet.http.HttpServletRequest;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.ServiceResultImpl
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.workflow.TransitionOptions
import static com.atlassian.jira.workflow.TransitionOptions.Builder;

@BaseScript CustomEndpointDelegate delegate

Deferred(httpMethod: "GET") {
MultivaluedMap queryParams,String body, HttpServletRequest request ->

String theUrltoReturn = ""
String issueId;
String clonedMessage;
try {

issueId = queryParams.getFirst("issueId") as String
//test
IssueManager issueManager = ComponentAccessor.getIssueManager();
Issue issue = issueManager.getIssueObject(Long.parseLong(issueId));

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

// def baseURL = ComponentAccessor.getApplicationProperties()getString(APKeys.JIRA_BASEURL)

//theUrltoReturn = request.getHeader("reffer");
//theUrltoReturn = baseURL+'/browse/'+issue
theUrltoReturn = request.getHeader("referer");
DeferredTransition(issueId)
log.warn theUrltoReturn
}
catch (e) {
return Response.serverError().entity([error: e.message]).build();
}

Response.temporaryRedirect(URI.create(theUrltoReturn)).build()

}

void DeferredTransition(issueId) {
try {
Issue issue
if (isNumeric(issueId)){

issue =
ComponentAccessor.getIssueManager().getIssueObject(Long.valueOf(issueId.toString()));
}

else{
issue =
ComponentAccessor.getIssueManager().getIssueObject(issueId.toString());

}

IssueService issueService = ComponentAccessor.getIssueService()
int actionId = 241// Deferred
TransitionValidationResult transitionValidationResult
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setApplyDefaultValuesWhenParameterNotProvided(false);
issueInputParameters.setSkipScreenCheck(false);
TransitionOptions trasitionOptions = new Builder().skipPermissions().skipValidators().setAutomaticTransition().skipConditions().build();

transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId, issueService.newIssueInputParameters(),trasitionOptions)

if (transitionValidationResult.isValid()) {
issueService.transition(currentUser, transitionValidationResult)
}
else {
log.warn("The transitionValidation is not valid")
}

} catch (Exception e) {
log.warn(e)
}
}

boolean isNumeric(String inputData) {
return inputData.matches("[-+]?\\d+(\\.\\d+)?");
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

214 views 1 6
Read article

Atlassian Community Events