Hello all,
I am working on creating an automated email which will link to specific confluence pages based on the selection of options in a custom multi-select field. If option 1 is selected I would like the email to include a link to page 1. If option 2 is selected, then I want to inlcude a link to page 2, and so on.
I have this section of code which runs but doesnt seem to work correctly
{{#issue.customfield_11131}}
IDs: {{id}}
{{#if (id == '13603')}}<a href="https://www.google.com/">Test</a>{{/}}
{{/}}
I get the following results
IDs: 13603
IDs: 13604
It appears that the if statement is not evaluating as true. But I dont know why not.
Thank you.
Josh
I have not worked with the conditional statements before but it looks like perhaps you need to do it this way:
if(equals(id, '13603'))
Hi @Josh.Updyke
Adding to Trudy's answer...
The reasons your condition is not evaluating to "true" are that you are trying to use iteration syntax with the custom field, and the test is on id attribute without any condition, as Trudy described.
Perhaps try this:
{{#if(equals(issue.customfield_11131.id,13603))}}<a href="https://www.google.com">Test</a>{{/}}
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 advice. I tried taking your suggested code and testing it. The email does not include the link. I believe this is because the IF statement is evaluating to false.
however, if I look at the data the rest API
<mydomain>/rest/api/2/issue/SR-3284?expand=names
I can see the following:
"customfield_11131": [{"self": "https://smith-nephew.atlassian.net/rest/api/2/customFieldOption/13603","value": "High Speed Surfacing (3 Points)","id": "13603"},{"self": "https://smith-nephew.atlassian.net/rest/api/2/customFieldOption/13604","value": "Aspect Ratio > Four (2 Points)","id": "13604"},{"self": "https://smith-nephew.atlassian.net/rest/api/2/customFieldOption/13605","value": "Tight Tolerance (2 Points)","id": "13605"}],.
I am not sure what I am doing wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Interestingly I was able to get this section of code working:
<b>Modifiers Impacting Manufacturing Complexity:</b> {{issue.customfield_11131.value}}
{{#issue.customfield_11131}}
{{#if (equals(value,"Aspect Ratio > Four (2 Points)"))}}Test 1{{/}}
{{#if (equals(value,"High Speed Surfacing (3 Points)"))}}Test 2{{/}}
{{#if (equals(value,"Tight Tolerance (2 Points)"))}}Test 3{{/}}
{{/}}
This isnt ideal though becuase if someone changes the value then my email automation will break. I have read that it is better to use the ID because that should never change even if someone changes the wording on the fields.
Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is interesting, Josh...
My understanding is the id attribute is a number field, but I wonder if equals() is doing some type casting. What if you treat it like text by wrapping the value in quotation marks?
{{#if(equals(issue.customfield_11131.id,"13603"))}}<a href="https://www.google.com">Test</a>{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had that idea as well and tried it. Below is the code I tested:
<b>Modifiers Impacting Manufacturing Complexity:</b> {{issue.customfield_11131.value}}
{{#issue.customfield_11131}}
{{#if (equals(id,"13603"))}}Test 1{{/}}
{{#if (equals(id,"13604"))}}Test 2{{/}}
{{#if (equals(id,"13605"))}}Test 3{{/}}
{{/}}
And here is the email I get back:
Modifiers Impacting Manufacturing Complexity: High Speed Surfacing (3 Points), Aspect Ratio > Four (2 Points), Tight Tolerance (2 Points)
So the first section is working where it shows the values, but the If statements dont work.
Thanks in advance,
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Would you please try writing this to the audit log and observe the results. If that is a CSV list of numbers, that will confirm we do not need the quotation marks for text.
{{issue.customfield_11131.id}}
And...I wonder if the extra spaces in your expression after the "if" cause problems, so try removing those also:
<b>Modifiers Impacting Manufacturing Complexity:</b> {{issue.customfield_11131.value}}
{{#issue.customfield_11131}}
{{#if(equals(id,13603))}}Test 1{{/}}
{{#if(equals(id,13604))}}Test 2{{/}}
{{#if(equals(id,13605))}}Test 3{{/}}
{{/}}
By the way...a better solution for this scenario would be to use the Lookup Table feature, allowing you to use the iterator and get() on the field:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The results of
{{issue.customfield_11131.id}}
are
13603, 13604, 13605
I also tried removing the spaces and there was no change in the results. I still get the values of the custom field in in my email, but none of the if statements return true. I am not sure why it doesnt work.
Thank you for the suggestion about the lookup table and get(). I have never used those before, so I will do some reading and see if I can use that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey, Josh!
After pondering I realized a lookup table will not work for your scenario. The reason is that once the rule is inside of an iterator, nothing above that level of scope is visible. And so the table would not be visible for use.
I experimented a bit, learned a few things, and this example does work as you planned. I added a format("#") to force the format of the field.
<b>Modifiers Impacting Manufacturing Complexity:</b> {{issue.customfield_11131.value}}
{{#issue.customfield_11131}}
{{#if(equals(id.format("#"),"13603"))}}Test 1{{/}}
{{#if(equals(id.format("#"),"13604"))}}Test 2{{/}}
{{#if(equals(id.format("#"),"13605"))}}Test 3{{/}}
{{/}}
Here is more of what I learned:
Whew! Well at least you have something to use which does not require hard-coding the drop-down value text.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Bill,
Thank you so much for all your help. I am very excited implement this and it is going to have a big impact on my team. This will help to automate something my team is doing almsot evey single day at work. I just wanted to share with you the impact your help will bring.
While the lookup table wont help with this, you gave me another thing to think about. After reading about it, I think I have another automation which that look up table will be super helpful for. So while not helpful here, it was still helpful.
Once again, thank you.
Josh
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.