Forums

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

Show a new page with an error message if the issue does not have components

Mouna Hammoudi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 6, 2023

I am using a web fragement and a REST endpoint and I would like to show a screen letting the user know that the issue has no components, here is an example of the new page I would like to be shown after clicking the button if the issue does not have any components.

 

Capture.PNG

 

Here is my code below:

package SuperFeature 

import groovy.transform.BaseScript
import com.atlassian.jira.issue.Issue;
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.component.ComponentAccessor
import javax.ws.rs.core.Response
import com.opensymphony.workflow.WorkflowException

@BaseScript CustomEndpointDelegate delegate

mounaGenerate(httpMethod: "GET", groups: ["jira-users"])
{
MultivaluedMap queryParams, String body ->
def log1 = Logger.getLogger("atlassian-jira.log")
def issueId = queryParams.getFirst("issueId") as Long

Issue myissue = ComponentAccessor.getIssueManager().getIssueObject(issueId)
def issueKey = myissue.getKey()
def componentNames = myissue.getComponents()*.name

log1.warn("MOUNA componentNames "+componentNames)


if(componentNames.empty) {

log.warn("MOUNA EMPTY")
// WRITE NEW CODE HERE TO DISPLAY THE NEW PAGE SAYING THAT THE ISSUE
//DOES NOT HAVE COMPONENTS
throw new WorkflowException("Issue does not have components")

}else{
log1.warn("MOUNA componentNames NOT EMPTY")

}
}

 

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 11, 2023

Hi @Mouna Hammoudi

Can you please clarify when do you want this Validation to take place? Is it when the issue is being created or when you are transitioning it? I am asking this because, from your description, this seems easier to achieve with either the Behaviour or the Validation rather than using a REST Endpoint.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

Mouna Hammoudi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2023

when a button is clicked but I wanna write the page myself, I am using a web fragment for the button and then I am using a REST api.

 

Capture.PNG

Suggest an answer

Log in or Sign up to answer