Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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 to set numeric range [1-100] for custom field?

“Capacity” field should be an integer value between 1 and 100 inclusive. I’d like to validate that value and throw an error message if outside that range, typically validation done upon hitting “Create”.

1 answer

0 votes
Payne Community Leader Jul 06, 2021

Do you have any apps, such as ScriptRunner? Without one of those, I don't know if you can accomplish this.

Yes, I have ScriptRunner. 

Payne Community Leader Jul 06, 2021

In that case, one way to accomplish your goal is to create a "Simple Scripted Validator" with a Condition like this:

def capacityField = customFieldManager.getCustomFieldObjectsByName("Capacity")[0]
def capacityValue = issue.getCustomFieldValue(capacityField)
return capacityValue == null || ((int)capacityValue >= 1 && (int)capacityValue <= 100)

And an error message like this:

Capacity should have a value between 1 and 100, inclusive.

Like Nic Brough _Adaptavist_ likes this

Is it possible to write Behavior for capacity field?

I'm sorry but ScriptRunner is completely new for me...

I don't know how It'll show an error.

Will you please add complete code with an error.

I have written this code in behavior for capacity field.

but It shows an error the variable issue is undeclared.

plz correct code ....

 

import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.component.ComponentAccessor


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfValues = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Capacity")
def cValue = issue.getCustomFieldValue(cfValues)

if ((int)cValue < 1 || (int)cValue > 100) {
throw new InvalidInputException("Capacity field should be an integer value between 1 and 100 ")
}

Payne Community Leader Jul 07, 2021

For a "Simple Scripted Validator", there is a field where you type the error text that you wish to display on a failure.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Trello

🏊‍♀️ Atlympic Event: Trello

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

170 views 2 13
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