Forums

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

How to get Error Messages/Output (SCRIPTRUNNER)

Harvey Bennett March 25, 2021

The situation I have is as follow:

I need to wipe out the fields in a behavior when a new dropdown is selected. The problem is whenever I click create button and an error exist on the form it is wiping out the fields for some reason, even though I am checking for "getFieldsChanged()". I just figured at this point, an easy workaround is to check for any errors that would be returned and if some errors are returned, I'll just build an exception where the clear fields function is called. I have no idea how to get the error returned though... Is anyone able to provide me syntax on how to do this? This is what I've got going so far but the list is empty.

 

def jiraServiceContext = new JiraServiceContextImpl(user, new SimpleErrorCollection())

def errorList = jiraServiceContext.getErrorCollection()

log.debug(errorList.dump()) // currently outputting {}

 

Much appreciated

Harvey

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
March 27, 2021

Only ERROR level of "log" is logged by default. So

log.error(...)

function should work.

Or you need to setup logging level first using

log.setLevel(Level.DEBUG)

as described here

Harvey Bennett March 29, 2021

I have no issue outputting logs. Before I run my script I do

log.debug("START SCRIPT") 

which output no problem. But I need to catch errors returned on a create submission that fire back off because of validation results, read and interpret those results to help the user with the next time they try to hit the create button. I am doing this by refining the choices in the checkbox list.

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
March 30, 2021

Hi @Harvey Bennett , oh, ok, I understand now. But unfortunatelly I never tried to get errors this way. But I think that any "error collection" is filled in with data when Validators are executed and validators are executed when transition is executed. So you would need to validate validators any time the fields on the screen are changed.

I remember we used this method to validate transition

https://docs.atlassian.com/software/jira/docs/api/7.4.0/com/atlassian/jira/bc/issue/IssueService.html#validateTransition-com.atlassian.jira.user.ApplicationUser-java.lang.Long-int-com.atlassian.jira.issue.IssueInputParameters-com.atlassian.jira.workflow.TransitionOptions-

So it might help a little, but it will be still quite complicated code.

Suggest an answer

Log in or Sign up to answer