Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

134 views 1 0
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you