Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Edited

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

2 votes
Answer accepted

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 Mar 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 Jun 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. 

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 Jun 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. 

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

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 Jun 26, 2020

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

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 Jun 26, 2020

That's fantastic!

John Funk Community Leader Feb 07, 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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

495 views 16 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you