Remove return characters \r\n from ConnectWise Automate/LabTech Variables

A simple method when these are plaguing your script. It hit me again to day in the form of a script that wasn’t doing what I expected, it wasn’t until I looked at the output in a multi-line view did I see it was throwing in a return character in the middle of a command.

You can fix it using a quick SQL trim. BE AWARE THAT VARIABLES ARE SECURE OR YOU MAY PUT YOURSELF AT RISK OF SQL INJECTION HERE.

For removing crlf from multi-line values, you can use a different function. (It works just as well for the single rows, but there is an extra step needed so I prefer the previous method just to clean up one line of text.)
You first need a variable that is holding just a blank line. I am calling this @CRLF@. Then use the “Script String Functions – Replace” script function. Example with single and multi-line values, your script should look something like this:

First I used the “Variable Set” function. This is only needed once at the start of the script. I defined:

Then each time you need to remove the line feeds, call the “Script String Functions” function. I defined:

Thank you for Darren White for his Regex function and workings above! You can read his original post here http://www.labtechgeek.com/forum/viewtopic.php?f=3&t=3495&p=21491#p21491

2017-05-25T14:47:51+00:00

One Comment

  1. Marshall 8th November 2017 at 2:14 am - Reply

    Thank you so much!

Leave A Comment