I have an "Affects Branch/es" custom field, and I'd like to force to have only one of "Affects version/s" and "Affects Branch/es" filled - in our system filling none or both is invalid.
A tried the following code, but it does not work:
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def branchesField = getFieldByName("Affects Branch/es")
def branchesFieldStringValue = branchesField.getValue()
def versionsField = getFieldById("versions")
def versionsFieldStringValue = versionsField.getValue()
if (branchesFieldStringValue == null && versionsFieldStringValue == null) {
branchesField.setError("brancherror both empty 3")
}
if (branchesFieldStringValue != null && versionsFieldStringValue != null) {
branchesField.setError("brancherror both filled 4")
}
I think the problem is the way I checked if they're empty or not. I tried with converting them with .tostring() and comparing with "" and some other ways - but now I think I'm getting lost. Can someone help me?
Hello @Gergely Fehér
This is a Groovy script. Groovy is made to simplify this kind of things.
Try this:
if (branchesFieldStringValue && versionsFieldStringValue) {
branchesField.setError("branchesboth empty 3")
}
if (!branchesFieldStringValue && !versionsFieldStringValue) {
branchesField.setError("brancherror both filled 4")
}
Regards,
Adrien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I wrote the below code in behaviour script to check if the field is empty . It is working if it is empty.. however, If i enter something the error is not cleared. Please help ,
I need to clear the error message if there is something in the field.
def loc=getFieldById("customfield_10612")
if (loc) {
loc.setError("Please Enter loc")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do we check if the given field value is text or not in behaviour script in jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.