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

How to write validation for a particular field value change

Vineela Durbha October 18, 2019

I want to throw an error message on the screen on the change of a checkbox field. SO initially we are writing a JQL query to fetch the results and if results are greater than 1, and if user is trying to check a checkbox field..I should be throwing error.

We have used JWT validators for JQL query but it is stopping us from updating any field on the screen.

SO is there any way to restrict error message only a particular field

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 19, 2019

With Scriptrunner behavior, you can display a red error message just below the checkbox field as soon as the checkbox is clicked.

The tricky thing may be to decide how this script should behave (if at all) when an issue where it was previously checked is opened and the JQL query results now have a value.

If you only need this to run upon issue creation it is simple:

//only run on create (issue doesn't yet exist in the db)
if(!underlyingIssue){
def chkFld = getFieldById(getFieldChanged())
//normalize the checkbox value... behavior returns astring when single box is checked or array when you have more than 1
def checkBoxValue = (chkFld.value instanceof String) ? [chkFld.value] : chkFld.value
chkFld.clearError() //("Security was NOT checked")
if(checkBoxValue.any{it == 'LabelOfYourCheckbox'}){
//do your JQL search here
def resultCount = 1
if(resultCount>0){
chkFld.setError("JQL returned more than 1 result")
}
}
}
0 votes
Thorsten Letschert _Decadis AG_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 21, 2019

Hi everyone,

just adding the solution we came up with in the support ticket here in case someone else having a similar question.

The scenario of interest describes as follows: when selecting the option Yes on a select custom field Final Review, check whether there already are other issues with that option. If so, block the transition, if not, pass.

We were finally able to do so given the following expression:

%{15562} = "Yes" IMPLIES count(issuesFromJQL("project = 'SW Build Project' AND issuetype = 'Internal Build' AND 'Final Build' = 'Yes' AND 'Target SW Release' = '" + %{15484} + "' AND key != '" + %{00015} + "'")) = 0

The first part is the initial check of the Final Review field which means, the expression is always true, when the selected option is not Yes.

%{15562} = "Yes" 

The second clause states that if the option Yes is selected, the given query must return 0 results, meaning there must be no other issue with this option.

Cheers
Thorsten

TAGS
AUG Leaders

Atlassian Community Events