Has anyone else run into this problem?
The only thing I can think is that Behaviours is seeing the "none" option selected in the Project select list as a viable option, instead of not one of the real options at all.
Note: "none" is not one of the options configured for the select list. It's only showing up because we don't want to set a default value for this particular select list so Jira puts a "none" in the select list for you when the form first loads.
Hello, @Crystal Gummo
Actually, there is a workaround for this problem.
You can control field input by setErrror(), clearError() methods.
Just add add behaviour to the target field, and here script example:
Boolean isValid
if (!StringUtils.isEmpty(getFieldById(getFieldChanged()).getValue())) isValid = true
isValid? getFieldById(getFieldChanged()).clearError() : getFieldById(getFieldChanged()).setError("You must enter field value")
I really like this idea.
I got an error when I tried your code:
StringUtils is undeclared.
so I added a
import org.apache.commons.lang3.StringUtils;
And then got this error:
it seems to be an error between types (object vs string). But I tried a few different things and couldn't get it to resolve.
So, I tried to write something similar, but while this doesn't give an syntax error, it still lets a user submit a ticket with "None" selected in the dropdown:
def ProjectFieldValue = getCustomFieldValue("12515")
Boolean isValid = true
if (ProjectFieldValue.equals("None")) isValid = false
isValid? getFieldById("12515").clearError() : getFieldById("12515").setError("You must enter a Project")
Any ideas where to go from here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your method does not work, because it gives you the NullPointerExeption (ProjectFieldValue is null)
Static type checking in not important, in runtime groovy will cast types anyway.
If it bothers you too much you can just cast it as String
Try the code bellow, it should work
import org.apache.commons.lang3.StringUtils
Boolean isValid = false
if (!StringUtils.isEmpty((String) getFieldById(getFieldChanged()).getValue())) isValid = true
isValid? getFieldById(getFieldChanged()).clearError() : getFieldById(getFieldChanged()).setError("You must enter field value")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You rock!
It works like a charm, with just one drawback: The field in question starts off red with the error message, as soon as the user pulls up the form. It's kind of like yelling at them when they haven't had the opportunity to mess up yet. Any ideas on how to avoid that? I admit I can't think of anything and this solutions as-is is already so much better than what I had before.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A behaviour works as soon as a form loads, so it's imposible to postpone that moment with behavior.
If you want to check fields after the submit button was pressed, you can use the simple scripted validator on the create transition with a condition like this:
cfValues['project_field1']?.value != null
but the field will be required everywhere on issue create.
One more variation. Service desk has the "Customer Request Type" field , the value for the field is set only if an issue is created from the portal or email (via service desk handler). So you could try a validator like this:
cfValues['project_field1']?.value != null && cfValues['Customer Request Type'] != null
So if you have service desk mail handlers configured, you need to test this solution, if it affects issue creation via email.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! I've already marked your solution as the "accepted solution" because it was so much better than just living with the problem until the underlying bug is resolved.
I've already got your setErrror/clearError approach in place on our production system and people are happy.
Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are currently aware of bug SRJIRA-2810 which causes the system to consider "None" as a valid option when it shouldn't be.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, I'll start watching that ticket and close out this conversation.
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.