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

How do I set a character limit on a custom field using scriptrunner in Jira Cloud?

I am way out of my league here. I attempted searching the database for a script to use in scriprunner for my issue, but I have found that their answers didn't work for me. That could be because they are running scriptrunner on a server and not cloud. One solution was to use scriptrunner behaviours but I am unable to find that in the cloud version. Any help would be greatly appreciated. 

3 answers

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.

 

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

What app are you using to provide the regex?

Hi. This is provided via (JSU)

1 vote
Andy Heinzer Atlassian Team Apr 03, 2018

While I believe you can use scriptrunner to help with this, you could also just use a bit of javascript to help here.   @Andy Keyworth had a post over on https://community.atlassian.com/t5/Jira-Core-questions/Setting-a-character-limit-on-a-text-field-single-line/qaq-p/66709

with some example code, that @SABVARX also helped with.

What you can do is go into the field description in Jira, and then input a script like this:

<script type="text/javascript">
function validate()
    {   
        if(document.getElementById("customfield_19600").value.length >33)
        {
            alert( "Invalid length, must be no more than 33 characters" );
            return false;
        }   
    }
document.getElementById("customfield_19600").addEventListener("keypress", validate);
</script>

In this case, you would have to substitute the 'customfield_19600' with the customfield number this is, and you can also change the specific length you want these values to be.   I would recommend looking into How to find id for custom field(s)?  in order to find your custom field id.   And you also might need to review the documentation on Configuring a custom field in order to understand where you can edit the custom field description.

@Andy Heinzer 

I am also lokking for the similar usecase. I have tried this script , It seems working on create screen but on edit screen this validation is not working. Any suggestions.

Appreciate your help.

FYI -We are using jira server 7.6.6

Andy Heinzer Atlassian Team Mar 14, 2019

Hi Sudheer,

In hindsight of this answer, I think I actually prefer James Quinton's answer on this post over my own now.  The approach I originally suggested to use a javascript to limit a field length is flawed.  The main reason for this is that it does not cover all the ways that this field could be edited in Jira.  For example, if users access the REST API to create/edit issues, they would never see this field is restricted in any way.

Whereas with James' approach, the use of a workflow validator can prevent users from entering a value you do not want to see here in both input methods.   In his case, I believe he was using the JSU plugin to get this validator to work.  However I'm sure there are other plugins available in Marketplace for Jira that can also provide this same kind of validator functionality.  For example, the Workflow Enhancer for Jira also appears to offer regex validators, and it appears to be a free plugin at this time.

I get an error when using this script at:

<script type="text/javascript">

 

Is there a specific import package to be used?

Andy Heinzer Atlassian Team May 17, 2019

Hi Natalie,

I believe that changes to Jira Cloud have made my answer irrelevant to that platform.  If you're using Jira Cloud, you can no longer add these custom java scripts to places like field descriptions or the announcement banner in Jira Cloud.

These places could still be utilized for Jira Server platforms as a way to do this.  However the Cloud suite has restricted this ability.

I hope this helps.

Andy

Like Natalie Al-Delemi likes this

Thanks Andy for replying.. my bad I didn't notice this is all related to cloud. I'm actually using a server.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

224 views 2 1
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