Forums

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

How to limit filling a multiple choice field to a maximum of 5 items per ticket with JMWE?

rangel de oliveira machado
Contributor
August 2, 2021

Good Morning!.

I need to build a validation to limit the use of a field in a jira form.

I have a multiple choice field and in this field, a list with more than 40 options and I need to limit this field to only 5 items per ticket.

Example: team a, team c, team d, team f and team h. So that when reaching 5 options, validation does not allow the registration of the ticket with more than 5 options in the field and sends a message alerting that it can only have 5 items.

We have ScriptRunner, Automation and jmwe apps in our environment.

 

Jira Cloud

3 answers

2 accepted

2 votes
Answer accepted
David Fischer
Community Champion
August 2, 2021

Hi @rangel de oliveira machado 

using JMWE, you can use a Build-your-own Validator with something like:

! issue.customfield_10200 || issue.customfield_10200.length <= 5

where you'll need to replace  customfield_10200 with the custom field ID of your checkbox field (which you'll find on the "Issue Fields" help tab below the editor).

Joseph Chung Yin
Community Champion
August 2, 2021

@David Fischer -

We use JMWE add-on too and implemented your suggested solution too.  Both JMWE and ScriptRunner add-ons are excellent add-ons for any Jira env.

@rangel de oliveira machado -

In CLOUD env, you have to use groovy script for issue to obtain the custom field option counter.

Best, Joseph

1 vote
Answer accepted
Joseph Chung Yin
Community Champion
August 2, 2021

@rangel de oliveira machado - 

You need to obtain the size of your custom field (based on selected options) associated to the issue.  Here is a possible codes that I used in the past on determining the size (thanks to @Nic Brough -Adaptavist- response in an older case ask in the community)

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue)?.find { it.id == "<your multi select custom field id>" }

return issue.getCustomFieldValue(customField).size()

Once you obtained the size, then you can build the logic to raise an error when user selects more than five options to prevent issue from being created.

Hope this helps.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.

David Fischer
Community Champion
August 2, 2021

Hi @Joseph Chung Yin I'm afraid your answer only works on Server/DC, not Cloud, does it? Rangel mentioned he's using Jira Cloud when he raised his question.

Joseph Chung Yin
Community Champion
August 2, 2021

@David Fischer -

You are right.  Sorry for the missed...  Import class libraries are not supported in the CLOUD.  

@rangel de oliveira machado -

Even though my suggested solution is for Jira DC, the overall concept should still be applicable in the CLOUD env.

Essentially, you have to obtain the size of the field options (options selected by users) as a counter, and then use that counter value to raise your validation error during issue creation process.

Best, Joseph

David Fischer
Community Champion
August 2, 2021

Hi @Joseph Chung Yin 

the thing is, on Jira Cloud, you cannot write Workflow Conditions and Validators in Groovy, only in Jira Expressions. That's a limitation of Jira Cloud that ScriptRunner isn't immune to.

Best,

David

Joseph Chung Yin
Community Champion
August 2, 2021

@David Fischer -

Hi David:

Again, thanks for your insight and expertise.  My learning never stops.

Best, Joseph

0 votes
rangel de oliveira machado
Contributor
August 4, 2021

Good Morning!

Thanks so much for your help and sorry for the work. I will test now and return with feedback.

 

@Joseph Chung Yin  @David Fischer 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events