Recent searches


No recent searches

Suggestion: Add newline formatting in macros for Custom Ticket Fields (multi-line text)



Posted Dec 04, 2020

Hey everyone,

this request has already been posted in 2017, Gabe Castillo had the same issue as me and basically solved it the same way. However, I would love to have this as a native Zendesk functionality.

As you can see in this screenshot, the {{ticket.ticket_field_360033071872}} placeholder does not include any line breaks.

 

A quick glance at the ticket data via API however does show me that newlines are indeed registered in the ticket field as \n.

 

 

I tried different approaches to add newline formatting via Liquid Markup. 

Test 1:

{{ticket.ticket_field_360033071872 | newline_to_br}}

Expected behavior:

Robert Schwarz<br />Example Address 43<br />5931 Example City

Actual behavior:

Robert SchwarzExample Address 435931 Example City

 

Test 2:

{{ticket.ticket_field_360033071872 | replace "\n", "test"}}

Expected behavior:

Robert SchwarztestExample Address43test5931 Example City

Actual behavior:

Robert SchwarzExample Address 435931 Example City

 

These two tests lead me to the conclusion that the JSON newline \n is completely ignored, and not returned by the placeholder.

 

In case anyone else is facing this issue, here is my workaround solution:

1. Append a comma (",") before every lane break. As such:

Robert Schwarz,
Example Address 43,
5931 Example City

2. Split the string by comma (",") and print each part of the string in a new line.

{% assign address = ticket.ticket_field_360033071872 | split: "," %}
{% for line in address %}
{{ line }}
{% endfor %}

Result:

Robert Schwarz

Example Address 43

5931 Example City

We can see that it prints a full paragraph for each line created, which is still not the most beautiful solution. But at least it solves the problem temporarily. This method has a main caveat: Agents are always required to add a "," before a line break - this means a change in their workflow and something that can not be guaranteed in all instances.

 

To conclude this: I believe that newline formatting for textbox fields is something fairly trivial to implement and I would love to see native support on this in the future. Or at least give us a method to get the raw JSON value of a ticket field, such as:

Robert Schwarz,\nExample Address 43,\n5931 Example City

This would at least allow us to split the string by "\n".


1

5

5 comments

Hi Robert,

I came across this post facing a similar situation but managed to find a solution. You can use url_encode to convert \n to a usable url-safe set of chars to split on:

The following should work for you:

{% assign address = ticket.ticket_field_360033071872 | url_encode | split: "%0A" %}

 

1


Hey Andrew,

that's a much better approach than my workaround idea with commas! Thank you so much for the input :)

Best

0


This area is definitely not my forte. This is the code I'm using in my macro:

{% assign address = ticket.ticket_field_1260825395049 | url_encode | split: "%0A" %}
{% for line in address %}
{{ line }}
{% endfor %}

Which renders a result that's close but no cigar:

Does anyone know how to get rid of the + symbols? I know this is caused by the url_encode changing spaces into +, but I can't figure out how to work around this. 

0


Hi Kyle

Just used a similar solution to yours.

You can use the {{ line | url_decode }}, it will remove + symbols and all other previously encoded symbols.

{% assign address = ticket.ticket_field_1260825395049 | url_encode | split: "%0A" %}
{% for line in address %}
{{ line | url_decode }}
{% endfor %}

0


Julian Din Thank you!!! This worked like a charm. I owe you a coffee. 

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post