Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Script Runner Check Length of Custom Field

Marc Jason Mutuc
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.
Aug 16, 2018

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.

2 answers

Suggest an answer

Log in or Sign up to answer
3 votes
Mark Markov
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.
Aug 16, 2018

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.

Hi Mark,

 my custom field is titled "name". I'm getting this error

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 19, 2021

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.

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 16, 2018

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

@Nic Brough -Adaptavist- 

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("")
}
Sam Bartolome
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.
Dec 08, 2020

@Brian 

Your code is incorrect.

Your variable has different names around the code

The getFieldById is expecting an ID and a name is provided

TAGS
AUG Leaders

Atlassian Community Events