Can conditional operators be used in emails created by Automation Rules?

Darryl Lee - CCC June 25, 2020

I asked support about this, but figured it might be of interest to the community. Original Summary:

Can conditional operators be used in emails created by Automation Rules to hide fields that are empty?

 

We would like to send email notifications where fields are displayed only if they are not empty.

I tried this:

{{#=}}IF({{issue.Desired Delivery Date/Time}}!="","<b>Desired Pickup Date/Time:</b> {{issue.Desired Delivery Date/Time}}",""){{/}}

And got this error:

Error rendering smart-values when executing this rule:
Unknown operator ':' at position 17: IF(2020-07-10T20:00:00.0+0000!="",<b>Desired Pickup Date/Time:</b> 2020-07-10T20:00:00.0+0000,)

I tried surrounding the value with quotes

{{#=}}IF({{"issue.Desired Delivery Date/Time}}"!="","<b>Desired Pickup Date/Time:</b> {{issue.Desired Delivery Date/Time}}",""){{/}}

And got this:

Error rendering smart-values when executing this rule:
Missing parameter(s) for operator !=: IF("2020-07-10T20:00:00.0+0000"!="","<b>Desired Pickup Date/Time:</b> 2020-07-10T20:00:00.0+0000","")

Are the Math operators even able to compare string values?

Thanks!

 

2 answers

2 accepted

3 votes
Answer accepted
Darryl Lee - CCC June 26, 2020

JIRA Support got back to me with this answer, which I'm going to mark as correct. :-}

 

We recently added to support to conditional fields in automation actions and now you can perform some of those logic validations in the action item itself. The syntax would be something like that:

{{#if (issue.duedate.jiraDate.isNotEmpty()) }}
 test: {{issue.duedate}}
{{/}}

The following article will cover this in more details:

Additionally, I successfully tested some other field types:

Priority:

{{issue.description}}
{{#if (issue.priority.isNotEmpty()) }}
<b>Priority:</b> {{issue.priority.name}}
{{/}}

 Single-Select Field:

{{#if (issue.Destination.value.isNotEmpty()) }}
<b>Destination</b>: {{issue.Destination.value}}
{{/}}
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 18, 2021

Ohai - I had forgotten about this answer until somebody recently liked it.

As it turns out, it looks like Automation doesn't even require the isNotEmpty:

I recently used this for a cascading field value:

<b>CRM Access Requirements: {{issue."CRM Access".value}}{{#if(issue."CRM Access".child.value)}} - {{issue."CRM Access".child.value}}{{/}}</b>

It's probably good practice to use it though.

1 vote
Answer accepted
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 26, 2020

Hi Darryl,

I doubt Automation For Jira is going to be able to do what you have in there, but will let Support provide you with the expert response. 

Have you thought about filtering out those emails using JQL and then creating your Email rule just against the appropriate filter(s). You might need to create multiple rules to send various versions of the filters. 

Darryl Lee - CCC June 26, 2020

Hi, yes, looking forward to what Support has to say.

To provide some context, this is a Rule happening On Create for a JSD project that has 6 different Request Types that have slightly different sets of fields.

So the email currently looks like this:

Hello ________ – thank you for your Services Request.

Summary: Move stuff into Lab
Description:
Unpack crates and move equipment into Lab

Requesting Department: Special Projects
Destination:
Desired Pickup Date/Time:
Desired Delivery Date/Time: 2020-06-30T13:00:00.0+0000

But for Services Requests, there is not a Destination or Pickup, so ideally those empty fields would be hidden.

I'm trying avoid having to create a separate email template for each Request Type, since they're *almost* the same except for a few fields. 

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 26, 2020

You could do a single rule but have nested if/then statements for each Request Type. Then Copy and paste the email under each Request Type and edit out the fields that would be blank. 

Darryl Lee - CCC June 26, 2020

Right, I know I could do it in one rule with if/thens. I guess I just miss Velocity templates. :-}

Like John Funk likes this
Darryl Lee - CCC June 26, 2020

Good news from Support!

We recently added to support to conditional fields in automation actions and now you can perform some of those logic validations in the action item itself. The syntax would be something like that:

{{#if (issue.duedate.jiraDate.isNotEmpty()) }}
 test: {{issue.duedate}}
{{/}}

The following article will cover this in more details:

 

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 26, 2020

That's awesome!! Thanks for seeing that through! Have you tried it yet? 

Darryl Lee - CCC June 26, 2020

Indeed I did, and it works like a charm! The test code worked as advertised (although requiring jiraDate thing is a bit weird. But it definitely didn't work without it).

Other fields were more straightforward and worked fine.

Priority:

{{issue.description}}
{{#if (issue.priority.isNotEmpty()) }}
<b>Priority:</b> {{issue.priority.name}}
{{/}}

 Single-Select Field:

{{#if (issue.Destination.value.isNotEmpty()) }}
<b>Destination</b>: {{issue.Destination.value}}
{{/}}
John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 26, 2020

That's fantastic!

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 7, 2021

Hey @Darryl Lee - CCC  - Can you click on the Accept Answer above so people will know there is a solution to this one? Thanks!

Like Darryl Lee likes this
Suresh Srini July 7, 2021

I have field name with space and not able to get it working. It's custom field. Tried with field ID as well.

{{#if (issue.customfield_10144.value.isNotEmpty()) }}
<b>Standard Reference Number </b>: {{issue.customfield_10144.value}}
{{/}}

{{#if(issue."Standard Reference Number".child.value)}} <b>Standard Reference Number:{{issue.customfield_10144}}</b> {{/}}

Both didn't work. I want this field( many other fields also) to be added to email content only when there is a value present. Trying to avoid having a block for each Issue type.

 

Thanks in advance for your help.

Jar Lady April 10, 2024

Does the conditional logic work for Jira software 8.20.10? 

Suggest an answer

Log in or Sign up to answer