JSON Encoding Script Help for Outbound Rest API - New Lines

jlaue
Kilo Sage

Hello - 

 

I am working on an outbound REST API integration using a Flow and Rest Step Action within Flow Designer.  I am struggling to figure out how to keep the new lines consistent from the Description (string) field on the Incident form. 

 

Here is the string field:

jlaue_0-1694635153957.png

 

Here is the script I am using in the Flow's Action Input:

 

function jsonEncode(str) {

   str = new JSON().encode(str);

   return str.substring(1, str.length - 1);

}

 

var desc = jsonEncode(fd_data.trigger.current.description + '');

return desc;

 

 

Here is how it looks in the outbound payload:

 

=========================

        "subject": " INC2224128 - test",

        "description": "test\r\ntest\r\ntest\r\ntest\r\ntest\r\n\r\ntesting multiple lines,  testing testing.  \r\n\r\ntesting multiple lines,  testing testing.  \r\ntesting multiple lines,  testing testing.  \r\n\r\n\r\ntesting multiple lines,  testing testing.  \r\n\r\n\r\ntesting multiple lines,  testing testing.  \r\n\r\n\r\n\r\n\r\n\r\ntesting multiple lines,  testing testing.  \r\n\r\n\r\ntesting multiple lines,  testing testing.  \r\n\r\n\r\n\r\ntesting multiple lines,  testing testing.  \r\n\r\n\r\n",

        "priority": {

            "name": "Normal",

=========================

 

Here is how it looks in the target system:

 

jlaue_1-1694635331509.png

 

I am wondering if I am able to modify the script so that when it hits the target system, it will actually include the ‘new lines’ as they appear in the source field, as opposed to running them all together like the screenshot above.  Or if there is another way to go about this within Flow Designer?  

 

Thanks!!!

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, unfortunately your post does not contain clear details of your target platform or details of the received payload, but testing the supplied string in a PDI's REST API explorer I do not see the same behavior and the text formatting is correctly displayed.

Does the 'description' field of your target platform allow multiple row data or is it a single line text field?

Does the target platforms API documentation contain any details regarding the need to escape special characters?