Scriptrunner - Behaiviour: how to stop updating an issue because of an specific condition

Günter Halmans November 7, 2018

Currently, I'm trying to define two conditions regarding the component field in a subtask:

  1. the field should be required --> I realized this requirement setting the specific option in the corresponding field configuration. Everything fine.
  2. the field should only contain one component, not more and not less than one...

I tried to define a behaviour with respect to the specific project and field. I was successfull in checking the amount of components in the specific subtask and to send a user message or an invalid input message.

Now my question: When I'm entering two components in the edit dialogue the behaviour fires, but jira updates the issue (what I wanted to avoid) although the behaviour throws the exception.

Here is the snapshot of my behaviour code:

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("ITP-25")
def NumberComponents = issue.getComponents().size()
log.debug "NumberComponents: " +NumberComponents

if (NumberComponents != 1){
     throw new InvalidInputException("component", "Only one component is allowed")
     return null
}

I tried some alternatives, e.g. "return false" or throwing the invalidInputException without the assignment to the field...but nothing helps. Thus, I assume I'm not on the right track...

Has someone an idea? Thanks a lot in advance!

 

1 answer

1 accepted

0 votes
Answer accepted
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2018

Hi @Günter Halmans

Have you tried

somefield.setError("Only one component is allowed")
Günter Halmans November 7, 2018

No, I'm going to try it in a few minutes :-)

what kind of object is "somefield"?

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2018

the field you would like the error message to show against - maybe the Components field would work, not sure

your code will also have to clearError() when the condition is clear

Günter Halmans November 7, 2018

Hi Tom,

it works! Thanks a lot -  You have saved some painfull hours of my time :-)

best regards,

Günter

Suggest an answer

Log in or Sign up to answer