Trigger - Count Attachments | Community
Skip to main content

Trigger - Count Attachments

  • July 30, 2021
  • 2 replies
  • 0 views

Hello, I'm using the following code in a trigger.

{% for comment in ticket.comments limit:1 offset:0 %}
{{comment.value_rich}}
{% for attachment in comment.attachments %}
{{attachment.filename}} - {{attachment.url}}
{% endfor %}
{% endfor %}

Can I check in the loop whether the comment has an attachment in order to show additional text? Something like that 

{% for comment in ticket.comments limit:1 offset:0 %}
{{comment.value_rich}}
{% IF COMMENT HAS ATTACHMENTS %}
Notice: You have to log in to be able to download the attachment. If you don't have an account yet, click Send Password. 
{% for attachment in comment.attachments %}
{{attachment.filename}} - {{attachment.url}}
{% endfor %}
{% ENDIF %}
{% endfor %}

What would be the right condition?

This topic has been closed for replies.

2 replies

ZZ55
  • July 30, 2021

Linus

Try this:

{% for comment in ticket.comments limit:1 offset:0 %}
{{comment.value_rich}}
{% unless comment.attachments == empty %}
You need to log in to download attachments.
{% for attachment in comment.attachments %}
{{attachment.filename}} - {{attachment.url}}
{% endfor %}
{% endunless %}
{% endfor %}

  • Author
  • August 3, 2021

Hi Graeme, that is the solution. Great!