Forums

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

Need help in transition issue rest endpoint

Kavya May 3, 2024

Hi Team,

I need help in scriptrunner rest endpoint creation for transition issue.
I have one requirement where using fragment we need to transition issue or transition screen should popup once we click on that fragment, I created the fragment for that, but in rest endpoint creation I am facing issue, please help me to create rest end point to transition issue. If anybody aware please reply as soon as possible.

Regards,
Kavya 

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 6, 2024

Hi @Kavya

In your description, you mentioned:-

I have one requirement where using fragment we need to transition issue or transition screen should popup once we click on that fragment, I created the fragment for that, but in rest endpoint creation I am facing issue, please help me to create rest end point to transition issue. If anybody aware please reply as soon as possible.

I am going to assume that you are trying to Use Web Item to display a dialog box. Please clarify.

Please clarify: Are you trying to trigger this when transitioning the Issue? 

It would be helpful if you could share a screenshot of your configuration and the REST Endpoint code so I could review it and provide some feedback.

Thank you and Kind regards,
Ram

 

 

Kavya May 6, 2024

Hello ram,

Thank you for your reply!

Yes, we have created the custom web item to display dialog box.

I created one rest endpoint which is shared below(I just copied it from one of the community post) and copied this transition issue rest endpoint link and used in the fragment by selecting "Navigate to link" option.

Actually when I click on the fragment/dialog box it is taking me to the black screen instead it should take me to one of the transition screen, so please help me to correct the rest endpoint code.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import groovy.json.JsonBuilder

// Define the transition function

def transitionIssue = { issueKey, transitionId ->

    def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)

    if (issue) {

        def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

        def transitionValidationResult = ComponentAccessor.workflowTransitionUtil.validateTransition(user, issue, transitionId, [])

        if (transitionValidationResult.isValid()) {

            def transitionResult = ComponentAccessor.workflowTransitionUtil.transition(user, transitionValidationResult)

            if (transitionResult.successful) {

                return "Issue $issueKey transitioned successfully."

            } else {

                return "Failed to transition issue $issueKey: ${transitionResult.errorCollection?.toString()}"

            }

        } else {

            return "Failed to validate transition for issue $issueKey: ${transitionValidationResult.errorCollection?.toString()}"

        }

    } else {

        return "Issue $issueKey not found."

    }

}

// Define the REST endpoint function

def transitionIssueEndpoint = { req, resp ->

    def requestBody = req.JSON

    // Extract issueKey and transitionId from the request body

    def issueKey = requestBody.issueKey

    def transitionId = requestBody.transitionId

    // Check if issueKey and transitionId are provided

    if (!issueKey || !transitionId) {

        resp.setStatus(400)

        return new JsonBuilder(["error": "Issue key and transition ID are required."])

    }

    // Perform the transition

    def result = transitionIssue(issueKey, transitionId)

    // Respond with the result

    new JsonBuilder(["message": result])

}

// Expose the endpoint

//post("/rest/scriptrunner/latest/custom/transitionIssue") { req, resp ->

  //  transitionIssueEndpoint(req, resp)

//}

transitionIssue(httpMethod: "POST") { req, resp ->

    transitionIssueEndpoint()}

request.getParameter(req, resp)

 

Regards,

Kavya Janiwarad

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.11.2
TAGS
AUG Leaders

Atlassian Community Events