jirajira-rest-apijira-pluginjira-rest-java-apiscriptrunner-for-jira

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


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

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")

}

Solution

  • When you use ScriptEunner WEB Console, you should return some value, throwing the Exception will not work in most cases. You can structure the code of the script in such a way that you break/stop operation or return false/null/etc. depending on who is the consumer of the Error/Exception.