Embedding JSON inside Liquid IF Statement in Zendesk trigger for Webhook



2024년 4월 26일에 게시됨

The objective was to synchronize the "End user" field with an internal field with the same name for its field options. However, not all of the internal field's options can be made available to end users, so two separate fields were needed. While achieving this using multiple triggers is possible, it becomes cumbersome when there are more than 20 field options, as it would require creating 20 or more triggers for each option.

 

Create a trigger

in action notify webhook ( I used Update Manay API /api/v2/tickets/update_many.json)

and in JSON body use this code

{% if ticket.field_option_title_123456789 == "Option_A" %}
{"tickets": [{ "id": {{ticket.id}}, "additional_tags": "product_option_a"}]}
{% else %}
{% if ticket.field_option_title_123456789 == "Option_B" %}
{"tickets": [{ "id": {{ticket.id}}, "additional_tags": "product_option_b"}]}
{% else %}
{% if ticket.field_option_title_123456789 == "Option_C" %}
{"tickets": [{ "id": {{ticket.id}}, "additional_tags": "current_option_c"}]}
{% else %}
{% if ticket.field_option_title_123456789 == "Option_D" %}
{"tickets": [{ "id": {{ticket.id}}, "additional_tags": "product_option_d"}]}

{% endif %}{% endif %}{% endif %}{% endif %

 

In the above code, I am using an if statement to check if the field option title machines a text in “ ”

if true, I am passing JSON to the webhook 

Otherwise, it's moving to the next if statement.

Zendesk trigger will report this JSON as having an error, but it does not; you can ignore the error.

 


0

1

댓글 1개

1900284415764 - did you have a question about the Liquid or is this meant to share what you've found with other users?  Looking at your code, I'm curious why you didn't use {% elsif %} ?

0


댓글을 남기려면 로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물