Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Runner Check Length of Custom Field

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

1 vote

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("")
}

@Brian 

Your code is incorrect.

Your variable has different names around the code

The getFieldById is expecting an ID and a name is provided

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

All you wanted to know about customer support KPIs

When working in customer support, it’s crucial to calculate, analyze and monitor specific numbers, called KPIs (Key Performance Indicators). They go hand-in-hand with customer satisfaction, problem d...

107 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you