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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,708
Community Members
 
Community Events
184
Community Groups

Scripted Behavior to restrict checkox selction upto 2 values on create screen

Hello Commity,

I am tring to restrict a checkbox field name "Flagged" to allow upto 2 values on create screen. The following script is working for when user select 2 options and throwing error if they select more than 2 values.

But script is aslo throwing error if they seclect 1 value and not select any value. 

looking for some help to optimize it.

import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil

def field = getFieldById(getFieldChanged())
def ComponentsField = getFieldByName("Flagged")
def selectedValues = field.getValue() as List<String>


if (selectedValues.size() <= 2){
ComponentsField.setValid(true)
ComponentsField.clearError()
}
else
//if (selectedValues.size() > 2)
{

ComponentsField.setValid(false)
ComponentsField.setError("Maximum 2")

}

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 03, 2023

Hi @Sudheer Kumar Vempala ,

please confirm that you put that code to Flagged field.

Then try the following code :

import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil

def field = getFieldById(getFieldChanged())
def selectedValues = field.getValue() as List<String>


if (selectedValues == null || selectedValues.size() <= 2){
field .setValid(true)
field .clearError()
}
else
//if (selectedValues.size() > 2)
{
field .setValid(false)
field .setError("Maximum 2")

}

Please let me know,

Fabio

Hello Fabio,

 

Thanks for the quick reponse. 

Yes correct script is mapped to "Flagged" field. 

I have tired the updated script with additon of "null" now script is working 0-selection and 2 but the weird part is still 1-sections is tworing error. 

I tired differnt version where count <=1 code is failing if user selcects one option.

if (selectedValues == null || selectedValues.size() <= 1
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 03, 2023 • edited

Hey @Sudheer Kumar Vempala ,

I probably get your issue. Please could you provide information about checkbox options? Probably there are spaces in your options

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 03, 2023

Try this code :

import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil

def field = getFieldById(getFieldChanged())
def selectedValues = field.getValue() as ArrayList<String>


if (selectedValues == null || selectedValues.size() <= 2){
field .setValid(true)
field .clearError()
}
else
//if (selectedValues.size() > 2)
{
field .setValid(false)
field .setError("Maximum 2")

}

Hello Fabio

 

here is the list 

  • Yes- Regression Coverage candidate
  • Yes- Monitoring/ Alerts candidate
  • Regression- Under Evaluation
  • Regression- Out of scope
  • Regression- In Progress
  • Regression- Implemented (Automation)
  • Regression- Implemented (Manual)
  • Regression- On hold due to data dependency
  • Monitoring- Under Evaluation
  • Monitoring- Out of scope
  • Monitoring- In Progress
  • Monitoring- Implemented

 

I tired with another checkbox field same Issue I see. 

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 03, 2023

Please try the script provided in my previous comment.

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 03, 2023

hey @Sudheer Kumar Vempala , did u test it?

Hello Fabio,

Thanks for your quick response and help.

Scrpt is working now. I will accept answer

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 03, 2023

@Sudheer Kumar Vempala  thanks for your feedback

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.4
TAGS
AUG Leaders

Atlassian Community Events