Conditional Validations
Asked by Ritika Kapoor:

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?


Answers:
author: Darryl Lee
body: Hi [@Ritika Kapoor](/t5/user/viewprofilepage/user-id/5205701) - 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:

* [Cloud Workflows - Using Jira Expressions](https://docs.polymetis-apps.com/cloud-workflows/features/expression-tester)
* [Cloud Workflows - Cookbook (Jodocus)](https://docs.polymetis-apps.com/cloud-workflows/cookbook/sub-tasks-closed)
* [JMWE - Use Cases](https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/1004732490/Use+cases)
* [JMWE - Configuring Workflow Conditions for Jira Cloud](https://www.innovalog.com/jira-blog/videos/23-jmwe-videos/123-video-conditions-validators-for-jira-cloud) (video)
* [JWT - Use Case Library](https://apps.decadis.net/display/JWTCLOUD/Use+case+library)
* [ScriptRunner - Workflow Extensions](https://scriptrunner-docs.connect.adaptavist.com/jiracloud/workflow-extensions.html)
* [Jodocus Blog - Various Jira Expression of the Week articles](https://medium.com/@jodocus)

This is done with [Jira Expressions](https://community.atlassian.com/t5/Jira-articles/Jira-Expressions-But-Why/ba-p/1694545).

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

* [Make a field required only for stories](https://apps.decadis.net/display/JWTCLOUD/Make+a+field+required+only+for+stories)

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**](https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/1005420569/Use+cases+for+validators#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"`

comments: author: Darryl Lee
body: Regarding those question marks... (Thank goodness for [documentation)](https://developer.atlassian.com/cloud/jira/platform/jira-expressions/):
> 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. :-}


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