How to do I check the length of a Custom Field that is a Text Field (single line)?
Need to validate if it is more than 10 characters. If it is 10 or less, it should throw an error.
I'm also planning to do this after checking the content of another field.
Hello @Marc Jason Mutuc
Or you can create simple scripted validator (with easy-to-read condition) like this:
cfValues['CustomFieldName'].length() > 10
and ignore static type checking error.
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.
What type of field is it? Unless it's a plain string (short text field), you'll probably need to convert it to something that has a .length function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you need something like the below (although you could do it in one hard-to-read line if you want)
def myField = customFieldManager.getCustomFieldObjects(issue)find {it.name == "My field name"}
def myFieldValue = issue.getCustomFieldValue()
if (myFieldValue.length() > 10) {return true}
// put some validator response and a return false here - it'll catch empty strings and anything shorter than 11 characters
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm trying to adapt your code, any reason why this doesn't work? Behaviour set to a custom field.
def acc = getFieldById("Acceptance Criteria")
if (acc.length() > 50) {
ac.setHelpText("The input is too long")
}
else {
ac.setHelpText("")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your code is incorrect.
Your variable has different names around the code
The getFieldById is expecting an ID and a name is provided
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.