Liquid If/Else problem
Hi,
I have found a similar post here:
https://support.zendesk.com/hc/en-us/community/posts/208931908-LIquid-if-else-not-working
I have a problem to get some liquid expressions in triggers running correctly. I have several triggers, which informs a user about a new comment in a ticket. We are using different triggers for different ticket groups and basically this works.
But we have agents of the same group in different locations. In the e-mail notification, I want the user to know, from where he was getting the answer.
For this I have tried an if-expression with Liquid, which is not working.
What makes me really confusing is that another if-expression in the same trigger is working without problems.
The first if-expression, which is already working does only differentiate a specific agent:
{% if current_user.id == 123456789 %}
Ms. {{current_user}}
{% else %}
{{current_user}}
{% endif %}
Later on in the trigger, I have the next if-expression, which is not working and I do not know why.
{% if ticket,group.name == 'Group A' or 'Group B' %}
Office Potsdam<br />Abt. RMA<br />
{% else %}
Office Sarstedt<br />Abt. RMA<br />
{% endif %}
The output of this if-expression seems to be always true. It doesn't matter to which ticket.group the ticket is assigned, it gives me always the output like true:
Office Potsdam<br />Abt. RMA<br />
This is really confusing. In another trigger I have a if-expression, which decides also by group, if a satisfaction.rating will be send out to the customer and this is working:
{% if ticket.group.name == 'Group A' or 'Group B' or 'Group C' %}
{{satisfaction.rating_section}}
{% endif %}
The difference is, that I do not have an {% else %} tag in this expression.
I have other triggers with the same problem, where the if-expression will be always true, no matter whicht metrics the ticket really have.
Does anybody have the same issues or a tip/workaround to solve this?
Thanks in advance!
-
Hi Oliver!
I am by no means a Liquid expert, but I'm wondering if the 'Group A' or 'Group B' condition might be the problem. Is an OR condition generally supported in Liquid?
We have a couple Community Moderators who are good with Liquid so I'm going to track them down and ask them to weigh in on this! Sit tight!
-
Hi Jessie,
thank you very much.
"The available Boolean operators are:
and
or"
(source: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers)
It is really confusing. I have if-expressions in multiple triggers, sometimes they work correctly, sometimes the expression is always true (even if it should be false).
And I have tried so many versions like
{% if ticket.group.name == 'Group A' or ticket.group.name == 'Group B' or ticket.group.name == 'Group C' %}
This also doesn't work. Don't know what is happening exactly.
I have solved the problem for now with creating more triggers. I have the conditions, which are not working with Liquid in the trigger now.
But I see the next problem is occuring...
If-expressions with the "ticket.tags" attribute seems to be also not working.
The following example won't work:{% for comment in ticket.comments %}
{% if ticket.tags contains 'tag_1' or 'tag_2' and forloop.last == 'true' %}
End
{% else %}
{{comment.value}}
{% endif %}
{% endfor %}With this expressions, I would like to have a comment history in the e-mail notification.
When having specific tags in the ticket, I do not want to show the earliest (first) comment (=submit) in the ticket history, only the word "End".As explained above, the if-expression with the ticket.tag attribute is always true and I'm getting always "End", even the ticket does not have such tags or it is not the last forloop.
I have also tried
{% assign tags = ticket.tags | split: " " %}
and then using the tags-variable in the if-expression - same result, always true.
This is strange :)
-
Now I have tried it with nested if-expression - again not working :(
{% for comment in ticket.comments offset:1 %}
{% if forloop.last == true %}{% if ticket.tags contains 'tag_1' or 'tag_2' %}{% break %}{% endif %}{% endif %}
{{comment.value}}
{% endfor %}But here the output is always the {{comment.value}} even it is the last loop and the ticket.tags contains 'tag_1' or 'tag_2' - But here it should completely end the forloop ("break") - it does not work :(
I absolutely don't know how this is happening.
-
Just to be up to date:
Now I have found out, that the if-expression with the "forloop.last" attribute is working.
{% for comment in ticket.comments offset:1 %}
{% if forloop.last == true %}{% break %}{% endif %}
{{comment.value}}
{% endfor %}This puts me out the comment history without the first ticket comment/submitting description (last forloop).
So I need a solution for the ticket.tags. I have found a workaround here:
https://support.zendesk.com/hc/en-us/community/posts/203413686-Using-zendesk-tags-in-liquid-markup
But I do not understand the liquid {% capture %} tag exactly. Can anyone help?
-
Hey Oliver!
I haven't had a chance to actually learn Liquid yet, so I'm afraid I can't be of any help. But I have brought this to the attention of our awesome Community Moderators, so hopefully they'll be able to give you some insight!
-
Hi, thanks again! :)
And no problem, I have posted a lot and I can totally understand, that you do not have a tip on each comment :)
Liquid is a really complex language.I just want you or the moderators to be up to date with what I'm doing.That's why I'm posting every step I've tried.
Maybe I get some help over here too:
https://support.zendesk.com/hc/en-us/articles/203662146?page=2#comment_115001689508I am in cheerful spirits that we get this solved :)
For now, I wish you a pleasent and sunny weekend! -
Problem solved within this thread:
https://support.zendesk.com/hc/en-us/articles/203662146?page=2#comment_115001701668
Finally! :)
-
Hey Oliver,
Glad to hear you got an answer to your question - thanks for updating the thread!
-
Hi There!
I don't know if this is the right topic for me to write my concern.
I'm trying to make a trigger that will notify specific email user for every update of a ticket.
I just can't find a proper placeholder for my condition.
here's the logic:
if a ticket update has a comment either public or internal
then {{ticket.comments_formatted}}
else {'predefined text'}
-
Hi Donald Cornel I can't find a placeholder that would do what I think you are wanting to do. You can use liquid markup to create dynamic content, but that content has to be based on something in Zendesk (like business hours or a ticket field) rather than a freestanding text block I believe. There's are quite a few examples linked in the Liquid Markup article.
Please sign in to leave a comment.
10 Comments