Forums

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

how can I use or condition when I add a validation?

jun lee
Contributor
March 30, 2022

I am a new user, so I don't know script well.

I know && when both conditions are satisfied, however I want a script using A condition or B condition or A condition & B condition.  In sum, script has to satisfy below cases.

case1) cfValues['A']?.value == 'Yes'

case2) cfValues['B']?.value == 'Yes'

case3) cfValues['A']?.value == 'Yes' && cfValues['B']?.value == 'Yes'

In addition, field A and B can be null.  So, if value is null, Jira hasn't prevent transition.

 

I tried below, but it doesn't work correctly.

 

import com.opensymphony.workflow.InvalidInputException

if (!cfValues['A'] && !cfValues['B'])
{cfValues['A']?.value == 'YES' && cfValues['B']?.value == 'YES'
}
else {
throw new InvalidInputException("A & B are not YES")
}
if (!cfValues['A'] && cfValues['B'] )
{ cfValues['A']?.value == 'YES'
}
else {
throw new InvalidInputException("A is not YES")
}
if ( cfValues['A'] && !cfValues['B'] )
{ cfValues['B']?.value == 'YES'
}
else {
throw new InvalidInputException("B is not YES")
}
if ( cfValues['A'] && cfValues['B'] )
{ cfValues['A']?.value == '' && cfValues['B']?.value == ''
}
else {
throw new InvalidInputException("")
}

0 answers

Suggest an answer

Log in or Sign up to answer