Hi!
I wanted to limite a text-field (multi-line) to max 1000 characters on creation transition, in scriptrunner I tried with this:
cfValues['customfield_10202'].length() < 1000
error: cannot evaluate "cfValues"
issue.customfield_10202.lenght < 1000? true: false
error: "issue.customfield_10202.length < 1000\" - operator \"<\" is not applicable to types: null and Number"
Would anyone help me with the correct expresion or I need cast the value of customfield?
Thanks
Regards
Hi @Angel
If you are one cloud, then your custom validator most likely is using Jira expression. In case of multi line text, it can be tricky, because it may be an ADF object. Here is an example how it can be handled:
let plainTextValue = value => typeof value == 'Map' ? new RichText(value).plainText : value ;
issue.customfield_10202 != null && plainTextValue(issue.customfield_10202).length < 1000
If you are looking for more examples, check out our Jira expressions library which includes a variety of useful examples.
Cheers
Hi @Angel,
Hope you're doing well! I just wanted to share that we've released what we call the 'Ultimate Validator,' which takes the burden of learning Jira Expressions off your shoulders. Below is an example of how a configuration looks when validating that a text field's character count is less than 1000.
I am leaving a link to the app's documentation if you are interested.
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Angel
The custom fields may return null
if they are not set, or their data type might not match the operation you're trying to perform.
Below is how I would code during a creation transition to limit a multi-line text field to a maximum of 1000 characters. Bear in mind that I haven't tested the code, but it is worth trying!
def customFieldValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject('customfield_10202'))
if (customFieldValue && customFieldValue.length() <= 1000) {
return true
} else {
invalidInputException.addError("customfield_10202", "The text field exceeds the maximum allowed length of 1000 characters.")
return false
}
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.