limit character on custom field

AMOL
Contributor
October 30, 2017

I have a text custom field and would like to limit it to 70 characters or less. Is there a way to do this so whenever this field is present on any screen it only allows 70 chars?

3 answers

1 accepted

3 votes
Answer accepted
Alexey Matveev
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.
October 30, 2017

Hello,

if you have Adaptivist Scriptrunner you can develop a behavior or validator. If you do not have Scriptrunner you can download JsIncluder plugin (https://marketplace.atlassian.com/plugins/ru.mail.jira.plugins.jsincluder/server/overview) and write custom javascript for create,  edit and view screen. 

AMOL
Contributor
October 30, 2017

Hello Alexey,

I currently use a regex validator in the workflow as follows:
[A-Z a-z 0-9 ,.-]{1,70}$

However I dont like this method. Also the error message is ugly (See attached).

 

char_limit.JPG

Like # people like this
Alexey Matveev
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.
October 30, 2017

OK.  It s also a solution :)

Alexey Matveev
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.
October 30, 2017

I will also try it.  Thank you

AMOL
Contributor
November 1, 2017

Ok. Still looking for a better way to do it.

AMOL
Contributor
November 1, 2017

Found it here:https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-set-a-length-size-on-a-custom-field-using-scriptrunner/qaq-p/554208

 

I am using behavior plugin

def field = getFieldByName("My Field Name")
if ((field?.value as String)?.length() > 70) {
field.setError("Length of the field should be less than 70 chars")
} else {
field.clearError()
}
Like # people like this
0 votes
PIERSON Cédric December 2, 2019

Do you receive an answer concerning your question?

You can add condition to your workflow and check that the max number of char is below 70.

Or you can create your own script field.

0 votes
James Quinton
Contributor
April 27, 2018

Hello.  You can resolve this by adding a regular expression check to the workflow transition.  Much simpler than a groovy script.

 

Go to Project Setting > Workflows

Edit the workflow for the affected issue type

Switch to Diagram mode

On Create transition, click on the Validators

Choose Add Validator > Regular Expression Check

 

If you would like to restrict the field to a specific length:  enter [0-9]{n}$

 

(n) reflects your desired field length.

Andy Hurley
Contributor
October 25, 2018

Neither of these options stop a user from changing the field AFTER doing the transition though as they both depend on a transition validation.

I was looking for something similar and it seems that if we can't absolutely stop a field EVER being longer than a certain length then there is little point restricting it SOMETIMES.

Ah, correction. It seems that BEHAVIOURS do apply at all times - looking into that now.

Michelle Gronwold
Contributor
January 4, 2023

Question, I have a single line text field that I have set up a Validator in a workflow transition to verify the text entered is only up to 200 characters long (below). But it is not working. Even if I enter just a couple of words in this field, I will get an error message below. Is it because it is a text field that allows spaces? I'm stumped

Regular Expression Check (JSU)

  • Field to be checked: Activity Rationale
  • Regular expression: ^[*]{1,200}$
  • Concatenate multiple values: false
  • Split on newline characters: false
  • Error message (optional): Activity Rationale field is limited to 200 characters

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events