Forums

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

Behaviour on fixVersion(s)

Andreas Lorz
Contributor
November 11, 2021

Hi,

what I want to do is to ensure, that the fixVersion field has to has at least one valid value*.

Empty fixVersion is also allowed.

*I define valid values as values that meet a certain regex like /S\d{8,8}/

e.g. 

  • "test" whould not be valid and therefore a error should be displayed.
  • "S20220101"; "test" would be a valid and a non valid value and should not throw an error.

Got the following code:

import java.util.regex.Pattern
import java.util.regex.Matcher

def fixVersionsField = getFieldById("fixVersions")
def fixversion = fixVersionsField.getValue() as Collection
def pattern = ~/S\d{8,8}/
def matcher
def isConform = false as boolean

Iterator itr = fixversion.iterator();
while(itr.hasNext()) {
Object element = itr.next();
matcher = element.toString() ==~ pattern
if(matcher.find()){
isConform = true;
}
}
if(!isConform){
fixVersionsField.setError("errormsg")
}
if(fixversion.isEmpty() || isConform){
fixVersionsField.clearError()
}

The code seems to work as intended but ONLY when release values are created in the first place. 

If the person that has the permission to create new release versions and creates a new one by simply adding/creating new value though the create/edit issue screen the behaviour doesn't recognize invalid values.

Does somebody has a solution for this. Thanks in Advance!

 

For clearification I attach this screenshots.

"test" is a releases that was created before issue editingexistingValue-test.pngexistingValue-test-works.png

"abc" is not yet created but will be created now

createdValue-abc.pngcreatedValue-abc-worksNot.png

1 answer

0 votes
Andreas Lorz
Contributor
November 12, 2021

I made a view simple test with log output within the script and it seems that the behaviour script is triggered by adding a new release version like 'abc' in the example above, but it doesn't recognize the value as it does with existing values.

Suggest an answer

Log in or Sign up to answer