Convert line break to \n in data action in Script

Hi,

I'm trying to use a data action where we send a message trough our legacy system, but getting an error when trying to send a message with a line break. I suppose it's due to it not being formatted to a \n instead of a line break which the API doesn't seem to like.

Is there a way to be able to add multi line text that replaces line breaks with \n?

I've tried to pick variable, interpolated text and text expression in the input but it doesn't seem to work.

Hello,

Where are you getting your message from (the one with a line break)?

If it is from an Input component on your script page (with Multi-Line enabled), the line break is already converted to \n
I just did a test - adding a multi-line Input component on my Script page and triggering a Data Action (passing the value of the variable as input of my Data Action) - and the line break is converted to \n already.

Regards,

Yeah, exactly! Well, I have a custom action that adds a text in the input component based on a display value in a drop down since I need to update multiple variables. When looking in the console when trying the script I can see that it adds the \n, but in the payload it adds a ↵ instead and getting a 500 internal error, so I'm looking in to esc.jsonString in the request template to see if that helps. I'll get back with results as a solution might help others :slight_smile:

1 Like

The solution actually worked. So adding esc.jsonString to the variable in the data action resolved the issue. The problem seems to be that it needed double escaping when the above velocity macro wasn't used.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.