How to use liquid in a trigger to convert {{ticket.tags}} to create a proper array?

Answered


Posted Oct 26, 2022

Hello!

Working with {{ticket.tags}} in a notify trigger action, I have been unable to convert the string output of {{ticket.tags}} back to an array to send.  Are there some examples you can provide? My attempts always lead to escaped double quotes inside the array structure 

my liquid: "tagFix": [{%assign tagFix={{ticket.tags}} %} {{ tagFix | replace:' ','","' |   prepend: '"'| append:'"'}}]

resulting output: "tagFix": [
\"_added_csm\",\"_country_andorra\",\"_alt_pin\",\"_case_update\"]

Does anyone have a solution for taking the output of {{ticket.tags}} and converting it to a proper JSON array with out the quotes escaped, for use in a notify webhook? Might there be some other placeholder that does return the ticket's objects tag array as an array? 

 

 

 


2

2

2 comments

      I'm also curious on this. I want to dynamically edit a tag that comes in on ticket creation to remove a specific part of its text, specifically the ":clone" in "department:clone". I'm also attempting to use liquid to achieve this but the changes refuse to get applied to the {{ticket.tags}} array

      0


      Hi Dave Kaminsky (Qumulo)!
      In our case we were faced with the same problem and just ended up sending the ticket.tags as a string to our backend and splitted it there. Is that a possibility for you?
      If not, I just tried a workaroud based on something else we did with another field, and it’s working for me (It is not the most beautiful thing)
      {% assign tags_array = ticket.tags | split: " " %}
      "ticket_tags": [
              {% if tags_array.size > 0 %}
                      {% for tag in tags_array %}		
                              {% if forloop.index < tags_array.size %}
                                      "{{tag}}",
                              {% else %}
                                      "{{tag}}"                                  
                              {% endif %}
                      {% endfor %}
              {% endif %}
      ]
      I don’t know if the {% if tags_array.size > 0 %} is really needed, could you try it and tell us if it worked for you?
      Cheers!

      0


      Sign in to leave a comment.

      Didn't find what you're looking for?

      New post