1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 10, 2017

No, because the order of validators does not matter.

Each validator is a simple yes or no question. If any one of them is a "no", the whole thing fails.

Think of baking a cake - you have validators like "do we have eggs", "do we have flour", and "do we have sugar" and "do we have butter".  If any of them are "no", the transition from "gathering ingredients" to "making cake" fails.  It is irrelevant what order you check for them.

I suspect your question is about a conditional flow of validation - if <something> = X, then check Y, but if <something> = Z, then do no further checks.  Is that what you're trying to do?

Anna Protopapa August 10, 2017

I just want to have the same order as the fields in the screen. I can add a new field in the beginning of the screen but the new validation will be executed as the last one.

Anna Protopapa August 10, 2017

I just want to have the same order as the fields in the screen. I can add a new field in the beginning of the screen but the new validation will be executed as the last one.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 10, 2017

But the order does not matter.  The only place you see the order is when you're an admin editing the workflow.

Anna Protopapa August 10, 2017

Assume you have many fields: first field, second field, third field.... When a user fills the form to create the issue and there are validation errors, he will have the alerts to fix the validation errors in the order that are the validations. So the validation for the 10th field may be before the validation of the first field.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 11, 2017

Ok, that's a good reason for it, but JIRA doesn't think that way, it just fails all validation without order, because in most cases, it doesn't matter.

You could remove all the validators and re-add them in field order, but there is a better solution.

Write your own validation script to replace the set of canned ones you're using now.  You can check every field you want to in one script, and return an error to the user listing all the fields they've missed or got wrong in one go.  That's better for the user too - if they've made five mistakes, they don't have to correct them one at a time.

Anna Protopapa August 13, 2017

Do I have to use Custom script validator for my own validation script insted of Simple scripted validator ? Where can I find an example?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 14, 2017

Yes, that's correct.

The snippet I use as a base checks that a value is set if the issue type is bug:

if (issue.issueTypeObject.name == 'Bug' & cfValues['DemoSelectList']?.value == 'Capital'){
        throw new InvalidInputException("Something to tell a user what went wrong")
    return false
}
return true

Anna Protopapa August 20, 2017

Hi again!

This is my snippet. I get an error for "InvalidInputException". Do I have to do some imports?

// Import Regex
import java.util.regex.*;
// Construct The Pattern to Match on
Pattern pattern = Pattern.compile("^([0-9]{1,6})\$");
// Check if the Order Number Field is a match

if (cfValues['Order Number'] == null || pattern.matcher(issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Order Number")))){
throw new InvalidInputException("Please enter a valid number!")
return false
}
return true

Suggest an answer

Log in or Sign up to answer