Simple Scripted Validator - "OR"

Sales_Ops August 20, 2019

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 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2019

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.. 

Suggest an answer

Log in or Sign up to answer