Forums

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

How to throw an exception because the issue has no components in ScriptRunner postfunction

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.
August 25, 2023 edited

I am using Scriptrunner and I would like to throw an exception because the issue has no components as shown below: 

Capture.PNG

How can I do that? 

I am using the following code and I am checking if the components are empty but the error is not thrown. How can I fix this?

package SuperFeature

import com.opensymphony.workflow.WorkflowException

def components = issue.components

log.warn("MOUNA COMPONENTS "+components)

if(components.empty) {

         log.warn("MOUNA EMPTY")

          throw new WorkflowException("Issue does not have components")

}

2 answers

0 votes
Heiko Gerlach January 31, 2025

Hi All, 

 

even if Nic assumes that this is running in a validator, I recommend thinking about adding your business logic to a validator instead of a post function, this way you have a better control and can better communicate with the end user. I just evaluated this issue for myself and for me this is the better option.

 

BR

HEIKO

0 votes
Nic Brough -Adaptavist-
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.
August 25, 2023

Try simply

if (issue.components.empty) {
throw new InvalidInputException("You must enter at least one component.")
}

I am assuming this is being run as a validator, and you are on a recent-ish version of Scriptrunner (v 7.11 or above)

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events