If then else for comments / emails
Asked by John McConnell:

Hello all;

I have banged my head. (still a newbie)

I want to write a comment or send email to include:

* Release / Fix Version: {{If Fix Version is empty, then "Release is TBD", else Fix version name}}

I have tried about 15 different examples found all over the place but not having any luck.

Can you point me in the right direction?


Answers:
author: John McConnell
body: Closing:

It sounds like what I'd like accomplish is not possible with a comment or email. Which is fine, I don't want to waste time if not possible.


author: Trudy Claspill
body: Hello [@John McConnell](/t5/user/viewprofilepage/user-id/3308879)

Were you making use of this reference?

<https://confluence.atlassian.com/automation/jira-smart-values-conditional-logic-1081351607.html>

It does not appear that the logic supports an else condition for Jira Data Center.

Does the structure of your rule enable you to use an If/Else Block condition instead, and format two different messages?

comments: author: John McConnell
body: Yes, I have attempted your recommendaiton link, but no data.

Blocks don't seem to be an option here.

example of message/email

{{Fix Version/s.value}} value  
{{Fix Version/s.name}} name  
{{Fix Version/s}} plain

<br />

{{#if(Fix Version/s.value.isEmpty)}}  
Release - TBD value  
{{/}}

{{#if(Fix Version/s.name.isEmpty)}}  
Release - TBD name  
{{/}}

{{#if(Fix Version/s.isEmpty)}}  
Release - TBD field only  
{{/}}


author: Trudy Claspill
body: Can you show us your entire rule? We are missing some information about the context within which you are trying to use this code.

If the context of this code is such that the action has a single issue in context then to reference the Fix Version/s field you should be using the smart value

{{issue.fixversions}

Fix Version/s is also a multi-value field, so if you want to look at the name of a specific Fix Version within that field you have to identify which one you want.

Reference: <https://confluence.atlassian.com/automation/jira-smart-values-issues-993924860.html>

I think you should be able to use

{{#if(issue.fixversions.isEmpty)}}  
Release - TBD value  
{{/}}

And you should be able to use

{{#if(not(issue.fixversions.isEmpty))}}  
{{issue.fixversions.first.name}}  
{{/}}

If the Fix Version/s field contains more than one value, how do you know which one you want to include in the message?

Or you could use an If/Else condition block in your rule, potentially

![Screenshot 2024-06-07 at 2.57.54?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/328722iC5431B950E68A2F7/image-size/large?v=v2&px=999 "Screenshot 2024-06-07 at 2.57.54?PM.png")


author: John McConnell
body: Hello thanks for the feedback.

The "code" will go in an email out to a distro of users but here is the comment with your code recommendation.

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/328726i958FD1EC9E798058/image-size/large?v=v2&px=999 "image.png")

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/328725i0FD8FC88CC517469/image-size/large?v=v2&px=999 "image.png")


author: Trudy Claspill
body: If you are going to use an If/Else Block condition like the example I provided, then you would not need the {{#if(.... {{/}} syntax within the message/comment content.

Just use the plain text:

Release - TBD


author: John McConnell
body: Hello Trudy;

This isn't a block workflow for the fix version, it is an email that gets triggered when the status is ready for dev, then we send an email with information, including the fix version to our business partner. So that is why I want to formulate the if value is empty then something, else value.

It sounds like what I'd like accomplish is not possible with a comment or email. Which is fine, I don't want to waste time if not possible.


author: Trudy Claspill
body: I think what you want to do is possible. I'm not clear why you don't think it is possible.

In this example I used the Comment action but you could use the same syntax in a Send Email action. The rule makes one type of Comment if Fix Version/s is empty, and another Comment listing the Fix Version/s values if the field is not empty.

![Screenshot 2024-06-11 at 1.45.17?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/329281i60F31BBE09C12B88/image-size/large?v=v2&px=999 "Screenshot 2024-06-11 at 1.45.17?PM.png")


Tags: data-center

jira-data-center