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!
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}}
{{/}}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Right, I know I could do it in one rule with if/thens. I guess I just miss Velocity templates. :-}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's awesome!! Thanks for seeing that through! Have you tried it yet?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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}}
{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's fantastic!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Darryl Lee - CCC - Can you click on the Accept Answer above so people will know there is a solution to this one? Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.