Forums

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

Conditional Validations

Ritika Kapoor
Contributor
June 1, 2023

Hi! I work in JIRA cloud. How do you add conditional validations in JIRA either using the workflow or Automation.

Use Case: All Issue types have the same workflow. Issue type Bug has a custom fields F1 and Story/Task have custom field F2.

When issue type is Bug and a F1 is null, give an alert error message. 

When issue Type is Story/Bug and F2 is null, give an alert error message.

I've used validators from workflows for common fields and it has worked. I know I can try to use automation somehow, but is there a way to give an alert error message?

1 answer

1 accepted

0 votes
Answer accepted
Darryl Lee
Community Champion
June 1, 2023

Hi @Ritika Kapoor - unfortunately Automation does not offer any interactive elements like an alert or error message, or to force a field to be populated like a validator can.

You will need to create a custom validator from a paid third-party add-on like in these examples:

This is done with Jira Expressions.

Here's a relevant example from JWT's Use Case Library:

The actual Jira Expression from that example looks like this:

issue?.issueType?.name == "Story" ? issue?.customfield_20002 != null : true

I have not had used any of these add-ons in a while, so it could be that one of them now has a "wizard" or some kind of assistant that helps you create validators without needing to learn Jira Expressions.

ALSO - man, it has been a while, so I do not know what the ? is for after issue and issueType

Oh, I forgot that JMWE has a very useful Field required Validator that can add a conditional validation. So that's probably a great way to go if you had JMWE or purchased it:

  • Add the Field required validator to the Start Progress transition.
  • Select the F1 field
  • Select the Conditional validation option
  • Input the following script in Validator scope section
    issue.issueType.name == "Bug"
  • Configure the error message: F1 must be filled out for Bugs

And then another validator but for F2 and with this conditional validation:

issue.issueType.name == "Story" || issue.issueType.name == "Task"
Darryl Lee
Community Champion
June 1, 2023

Regarding those question marks... (Thank goodness for documentation):

In expressions where such strict rules are not desired, use the optional chaining operator ?.. This operator behaves in the same way as regular member access, but with one crucial difference: when accessing the property fails, null is returned.

So I think that's just a failsafe in case ... there isn't an issue or an issueType? That seems... unlikely. But ok.

Boolean logic is... weird. At least to this non-programmer. :-}

 

Ritika Kapoor
Contributor
June 2, 2023

Thank you Darryl. This was very helpful. I guess I need to look for the 3rd party add-ons now. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events