How to set a length size on a custom field using scriptrunner behaviour in Jira cloud

Jyoti Mane
Contributor
May 4, 2023

I'd like to set a size in a custom field. I need allow only 65 characters

2 answers

0 votes
Vando Goncalves (e-Core)
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2023

Hi @Jyoti Mane 

Just to confirm, you're using Behaviors for Cloud, right?

I'm not sure if you will be able to do that, but other possible option would be using validators and setting this restriction in the create transition.

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.

You just need to set this on the required workflow transition (ideally after the initial field input is required)

(Originally posted here: https://community.atlassian.com/t5/Adaptavist-questions/How-do-I-set-a-character-limit-on-a-custom-field-using/qaq-p/762038)

0 votes
Joel Batac
Contributor
May 4, 2023

try this

 

def formField = getFieldById('customfield_XXXX')
def value = formField.getFormValue() as String
//formField.setAllowInlineEdit(false)

    if ((value).length() > 65 ) {
        //formField.setRequired(true)
        formField.setError("Max number of characters is 65")
    } else {
        formField.clearError()
        //formField.setRequired(true)


    }
Jyoti Mane
Contributor
May 4, 2023

Thanks @Joel Batac 

This code did not work in ScriptRunner Behaviours for JIRA Cloud.

Nic Brough -Adaptavist-
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.
May 4, 2023

I'm afraid Jira does not yet support SR's abilities to do a lot of things in Cloud, but we are working with Atlassian to try to get this sort of stuff added.

Like # people like this

Suggest an answer

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

Atlassian Community Events