Hi All,
I'm struggling with something that should have been very easy, and it probably is, but I'm just not seeing it :( I'm also sure someone has probably asked this question before, but I can't seem to find it. So, here I am.
I have an automation rule that generates an email triggered by a schedule, which queries some issues.
To keep this simple, all I want to do is determine if a number is odd or even and write the string "odd" or "even."
I started with the following in the content of my email:
{{#issues}}
Issue index = {{index}}
{{/}}
This returns just what I expected, a list of issue index values:
Issue index = 0
Issue index = 1
Issue index = 2
Issue index = 3
In order to determine if the index is odd/even, I do some math:
{{#issues}}
Issue {{index}} = {{#=}}({{index}} % 2){{/}}
{{/}}
The results:
Issue 0 = 0
Issue 1 = 1
Issue 2 = 0
Issue 3 = 1
So far, so good! Now I just need to evaluate the odd/even numeric value right? (only evaluating odd to keep it simple)
{{#issues}}
Issue {{index}} = {{#if(equals({{#=}}({{index}} % 2){{/}},1))}}Odd{{/}}
{{/}}
Unfortunately, this is where I hit the wall and get the error:
Error rendering smart-values when executing this rule:
Mismatched start/end tags: null != in template-11fdf479-9202-4944-accc-
bca5fa38ba64:4: {{#issues}} Issue {{index}}
= {{#if(equals({{#=}}({{index}} % 2){{/}},1))}}Odd{{/}} {{/}}
I have tried every permutation, method, conversion, and prayer that I can think of and nothing gets me the simple little word of "odd."
Where am I going wrong!? THANK YOU!
So after a bunch of Red Bull I came up with a work around using the RGB method... So if you are looking to have alternating row colors in your table, simply add the following to your <tr> tag:
<tr style="background-color: rgb({{#=}}IF({{index}}%2, 243, 208){{/}},{{#=}}IF({{index}}%2, 246, 224){{/}},{{#=}}IF({{index}}%2, 244, 227){{/}});">
Explanation:
Thanks, Dan! That's great!
I did not know the modulo operator could be used in a stand-alone condition. Must be the math operation wrapper that allows that, and it certainly opens up possibilities for the other operators.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dan Kane -- Welcome to the Atlassian Community!
Index cannot be used in functions (or apparently conditions) within the iterator. There is a defect for this in the public backlog for Jira Cloud automation, although it is unclear what the usage scenario was to drive that defect: https://jira.atlassian.com/browse/AUTO-1087
What is the problem you are trying to solve? Knowing that may help the community to suggest alternatives.
I recall an edge-case scenario from a couple of years ago, where a customer wanted to find a specific numbered item in a list. Index did not help and once inside of an iterator, no other scope data is visible. The work-around was to expand the list into a created variable, and then use inline iteration and the match function to dynamically find the item. Again...this was an edge-case.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the info @Bill Sheboy! I had hoped the Jira god would answer! ;)
I feared a bug would be the cause. It is odd though that I can use the index in a math computation, but not pass the result (even when converted to a string) into a simple IF conditional.
The use case is extremely basic. The email produced contains a table of issues, which we would like to see with alternating row colors. Since the target client is Outlook, everything must be done inline as there's no JavaScript or Head access for css.
Best regards and thank you again,
~Dan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yup, that is a good use case :^)
How about a work-around...if you do not care about consistency of the first row being the same color?
Try using the issue's id value instead, with inline math functions:
{{#lookupIssues}}{{#if(equals(id,id.divide(2).floor.multiply(2)))}}issue {{key}} has an even id of {{id}}; {{/}}{{/}}
This works around not having a modulo operator for inline math functions.
Oops...that was an unhelpful idea as there is no guarantee of alternating issue id values in the result set of issues!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know about the possibilities in Outlook, but if you can add this single CSS rule to your email somehow, then you won't need to work with the index at all and CSS will take care of finding odd/even indices.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aron Gombas Unfortunately, though the preferable solution, you're unable (as far as I know) to modify the <head> tag within the Outlook message in order to insert the CSS required.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Dan Kane I saw that you finally managed to solve the problem with the Handlebars expression, great work!
Also, let me note that most (all major?) browser accept the <style> tag even within the <body>. I don't know about Outlook, but it is rather likely that it would work with that, too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.