Developer User Group - September Meetup: Liquid

5 Kommentare

  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Thanks to Stephen Belleau for sharing a great tip on one of his use cases:

    A fun use case for liquid, we sometimes want to render something if a certain tag is present on a ticket. For example, each ticket will always have a tag that defines SLA and it is always formatted as "bronze_sla" or "silver_sla". So I iterate through the tags and check the last four characters for a match: (whitespaces added for code readability)

    {% assign array = ticket.tags | split: " " %}
    {%- for tag in array -%}
    {%- assign suffix = tag | slice: -4,4 -%}
    {%- if suffix == "_sla" -%}
    {%- if tag contains "bronze" -%}
    Bronze
    {%- elsif tag contains "silver" -%}
    Silver
    {%- elsif tag contains "gold" -%}
    Gold
    {%- elsif tag contains platinum -%}
    Platinum
    {%- endif -%}
    {%- endif -%}
    {%- endfor %}
    1
  • Alek Reed

    Hi Ahmed Zaid, do you have similar notes or a recording for the second part of this? Specifically, I am looking to test the attachment example you shared where we could use Liquid to parse through attachments, assign a variable to True if a specific filetype extension is found, then take action. Thank you in advance!

    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Alek Reed,

    Unfortunately we did not manage to record that session. However, I found a post where a member of the community wanted to take specific action on the ticket when a .har file is attached. You can find my solution for it here.

    If your use case is different, let me know and we can find a solution together.

    0
  • Alek Reed

    Thank you so much Ahmed Zaid

    I tried to keep up with notes in our training, and I captured the following, but it seems incomplete.  Do you happen to have this example saved that you showed? If not, no worries, I can test and adjust it:

    {% comment %}Iterating over ticket comments. Iterate over each attachment and if it has SVG filetype post internal note.

    {% endcomment %}







    {% assign hasSvgAttachment = false %}

    {% for comment in ticket.comments %}

    {% for attachment in comment.attachments %}

    {if attachment.filename contains "svg" %}{% assign hasSvgAttachment = true %}{% endif %}

    {% endfor %} 

    {% endfor %}







    {% comment %}

    Starting the Bulk ticket payload

    {% endcomment %}




    "tickets:" [{% if hasSvgAttachment %}

     { "id": {{ticket.id}},

    "additional_tags": ["has_svg_attachment"],

    "comment": {

    "html_body": "{{htmlBody}}",

    "public": false,




    }

    {% endif %}]

    }
    0
  • Ahmed Zaid
    User Group Leader Community Moderator
    Zendesk Luminary

    Hi Alek Reed,

    This looks about right. The {{htmlBody}} is not yet defined though. You can replace it with the comment you wish to add to the ticket. I think in Rafael Santos's use case it could have been a security warning to agents regarding SVG attachment. You can also use "body" instead of "html_body" for a simple plain text.

    Other than that, you may be missing a single curlybrace "{" before this line

    "tickets:" [{% if hasSvgAttachment %}

    Let me know if it runs well and remember that updating tickets via API carries potential risks.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.

Powered by Zendesk