Sometimes we need to transition issues (or “review” issues) from our usual Dashboard Jira gadget “filter results” with only one click. For this “trick” we need the plugin Scriptrunner for Jira.

First create a custom REST Endpoint with Scriptrunner to Transition the issues (and do more actions if they needed).

Example code:

  • Note: the name of the REST Endpoint is transitionIssue with 2 input parameters: issue_key and transition_id
  • Note: The REST function is protected only to be called by jira-users Jira group
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions

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.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Logger
import org.apache.log4j.Level
//def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)

@BaseScript CustomEndpointDelegate delegate

transitionIssue(httpMethod: "GET", groups: ["jira-users"]) { MultivaluedMap queryParams, String body ->
//transitionIssue(httpMethod: "GET") { MultivaluedMap queryParams, String body ->
    def issue_key = queryParams.getFirst("issue_key") as String
    if (!issue_key) return Response.serverError().entity([error:"NO_ISSUE_KEY"]).build();
    def transition_id = queryParams.getFirst("transition_id") as String
    if (!transition_id) return Response.serverError().entity([error:"NO_TRANSITION_ID"]).build();
    
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
	def projectManager = ComponentAccessor.getProjectManager()
    def issueManager = ComponentAccessor.getIssueManager()

	Issue issue = issueManager.getIssueObject(issue_key)
	Integer actionId = transition_id.toInteger() // The transition ID

	IssueService issueService = ComponentAccessor.getIssueService()
	ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
	TransitionOptions transitionOptions = new TransitionOptions.Builder()
        .skipConditions()
        .skipPermissions()
        .skipValidators()
        .build()

	IssueService.TransitionValidationResult result = issueService.validateTransition(currentUser,
        issue.getId(),
        actionId,
        issueService.newIssueInputParameters(),
        transitionOptions)

	if (result.isValid()) {
    	issueService.transition(currentUser, result)
	} else {
    	log.warn result.getErrorCollection().getErrors()
        return Response.serverError().entity([error:"TRANSITION_ERROR"]).build();
	}
    
    return Response.ok(new JsonBuilder([result: "OK", error: ""]).toString()).build();
}

Once created the REST Endpoint, we need a new HTML Scriptfield to show a checkbox in order to “Review” the tickets.

  • Note: In this example, if the ticket is in status “to be started” the checkbox is shown “unchecked
  • If the status of the ticket is “delivery input” or “closed” the check is shown “checked
  • In this example we have fixed the transition_id to 11, just change the url jira.example.com and transition_id to your values
String Key = issue.getKey()
String text = "";
if ( issue.getStatus().getName().toLowerCase() == "to be started" ) {
text = """
<input type="checkbox" value="first_checkbox" onclick='\$.get( "https://jira.example.com/rest/scriptrunner/latest/custom/transitionIssue?issue_key="""+Key+"""&transition_id=11",{ IssueKey: \""""+Key+"""\"}, function( data ){alert("Task marked as Input received. Moved to status Delivery Input");});' ></input>
"""
}
if ( issue.getStatus().getName().toLowerCase() == "delivery input" 
    || issue.getStatus().getName().toLowerCase() == "closed"  ) {
text = """
<input type="checkbox" value="first_checkbox"" checked onclick="return false;"></input>
"""
}

return text

Finally, just show the Scriptfield in the “filter results” standard Jira dashboard gadget

That’s all!

By MrAddon

.

Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s