Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Help with validator length limit

Angel
Contributor
December 16, 2024

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

 

2 answers

1 accepted

0 votes
Answer accepted
Maciej Dudziak _Forgappify_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2024

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 

Angel
Contributor
December 17, 2024

it works for me

Thanks!

Maciej Dudziak _Forgappify_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 6, 2025

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.

Paragraph_chars_count_780.gif

I am leaving a link to the app's documentation if you are interested.

Cheers

0 votes
Tuncay Senturk
Community Champion
December 17, 2024

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
}

 

Angel
Contributor
December 17, 2024

I get this error when I tried with your example

 

2024-12-17 12_29_08-Añadir una transición de flujo de trabajo Validator - Jira.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events