Dear Community,
I would need some help trying to count the elements from a formfield.
I set up a behaviour from scriptrunner, which should only allow one affected version in the ticket.
The list has always the size 0
This is my code:
FormField affectedVersions = getFieldById(AFFECTED_VERSIONS)
List<ProjectComponent> components = affectedVersions.getValue() as List
if (components.size() > 1) {
affectedVersions.setError("Only one affected Version is allowed!")
}
else { affectedVersions.clearError() }
Thanks :)
Niklas
Don't mix apples and oranges... and don't try to assign affected versions to project components.
That's probably where your problem lies.
Also, you would not get into this sort of trouble if you used the soft-typing in groovy. Try this:
def affectedVersionFld = getFieldByID(AFFECTED_VERSION)
affectedVersionFld.clearError()
def affectedVersions = affectedVersionsFld.value as List
if(affectedVersions.size() > 1){
affectedVersion.setError("Only on Affected Version is allowed!")
}
Thank you Peter,
I tried the code, but i get the same result.
my testcode is:
def affectedVersionFld = getFieldById(AFFECTED_VERSIONS)
affectedVersionFld.clearError()
def affectedVersions = affectedVersionFld.value as List
if(affectedVersions.size() > 1){
affectedVersionFld.setError("Only on Affected Version is allowed!")
}
affectedVersionFld.setError(affectedVersions.size()+"")
Result:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It won't work maybe because I want to check the size, when i create an issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where did you put this code? It needs to be in the "Affects Versions" config:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.