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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Simple Scripted Validator - "OR" Edited

I'm using Adaptavist Simple Scripted Validator to check the below on create:

 

A). I have a field "Global" - if a user fills it in as Yes, I want them to be required to fill out field "Users"

B). If a user fills in global = no, they have to fill out one of either Users, User Types, or Dataset. 

 

I have the script for A (below). How do I add in the script for B? Basically I want an either/or statement

 

cfValues['Global']?.value != 'Yes' || cfValues['Users']

1 comment

You could try something like this:

if(cfValues['Global']?.value == 'Yes'){
return (cfValues['Users'])
} else {
return cfValues['Users'] || cfValues['User Types'] || cfValues['Dataset']
}

 Or you could use a custom validator instead and target the error message based on the condition (cfValues is not available, so you'll need some code to read those values):

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def cfm = ComponentAccessor.customFieldManager

def globalCf = cfm.getCustomFieldObjectByName('Global')
def usersCf= cfm.getCustomFieldObjectByName('Users')
def userTypesCf= cfm.getCustomFieldObjectByName('User Types')
def datasetCf= cfm.getCustomFieldObjectByName('Dataset')

def globalVal = issue.getCustomFieldValue(globalCf)?.value
def usersVal = issue.getCustomFieldValue(usersCf)
def userTypesVal= issue.getCustomFieldValue(userTypesCf)
def datasetVal = issue.getCustomFieldValue(datasetCf)

if(globalVal == 'Yes' && !usersVal){
throw new InvalidInputException(usersCf.hiddenFieldId, "This field is required when Global = Yes")
}

if(globalVal == 'No' && !usersVal && !userTypesVal && !datasetVal ) {
throw new InvalidInputException(globalCf.hiddenFieldId, "When you select No, you must complete either 'Users', 'User Types' or 'Dataset'")
}

 

Come to think of it.. it might be easier to have 2 separate simple scripted validation configurations and target the message that way.. 

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

907 views 2 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you