Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I prevent a required custom field from accepting only spaces?

Kmmaughs
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.
August 30, 2019

We have an issue where we need descriptions to be added to certain asks. Some of the engineers don't want to fill the data in and just type a space or a bunch of spaces in the required custom text field. How can I prevent this from being accepted?

 

I found this article: https://community.atlassian.com/t5/Jira-questions/Can-I-prevent-leading-and-trailing-whitespace-for-single-line/qaq-p/275894 which looks close to what I need, but I'm not sure how to write out the custom field name. 

 

This article was also close https://community.atlassian.com/t5/Jira-questions/Validator-to-restrict-spaces-on-custom-field-text/qaq-p/865782, but if they actually type in a description, then that's not quite what I'm looking for either. 

 

Any assistance with writing the groovy script (post function) that may be needed would be helpful.

1 answer

1 vote
Mikael Sandberg
Community Champion
August 30, 2019

I would put the check as a validation on the transition instead of a post function. Post functions will not prevent the user from just adding spaces to the description, if you do it as a validation the issue cannot move forward until the conditions are right.

But I would consider a different approach, because setting a validation only teaches the developers a different way of bypassing it. I would consider training them on how to write issues, and perhaps have a gate keeper (maybe their managers) that checks the issues to make sure the developers following the process. If the do not write a good description, push the issue back to them to correct it. A tool can do so much, but if a developer does not want to follow a process they will find a way around it. 

Kmmaughs
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.
August 30, 2019

A validator makes sense. I definitely agree with training. The field is already a required field. Assuming I needed to so a Simple Scripted Validator, what would that look like? 

I was trying to see if something like

!cfValues["FIELD_NAME"]?.value.contains(" "

would work, but I don't want to prevent any/all spaces from being entered. Rather, I want to make sure the first character is not a space. 

Mikael Sandberg
Community Champion
August 30, 2019

Something like this should do it. This will remove any leading white spaces and compare it to the original description value.

String desc = issue.description
if (desc.trim() !== desc) {
    // error
}

But it will not prevent anyone from enter a dot or any other character that is not a space.

Kmmaughs
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.
September 3, 2019

Thanks for sending this. I've been trying it out and getting a huge compilation error. Trying to resolve that. Until then, I'll let you know how it goes. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events