You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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+)?");
}