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
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).
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.
In CLOUD env, you have to use groovy script for issue to obtain the custom field option counter.
Best, Joseph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are right. Sorry for the missed... Import class libraries are not supported in the CLOUD.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David:
Again, thanks for your insight and expertise. My learning never stops.
Best, Joseph
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good Morning!
Thanks so much for your help and sorry for the work. I will test now and return with feedback.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.