How to preserve line breaks using a CDS with Dynamics
I have a Multiline Text field in Dynamics365 that I want to use in my Power Automate Flow. I also want to ensure that the line breaks or carriage returns are preserved and I don’t get a blob of text to use.
The challenge I found was how to isolate the specific carriage return. I had tried the usual ‘\n\ or ‘\ln’ etc without success.
Initially, just using the field output a block of the text. One Huge mass of words. It wasn’t very intuitive to read and I suspect if you’re reading this then you’re having the same issue, so let’s get on with this.
In my use case, I was starting with the input of a CDS Get Record and needed to output an HTML text block so that I could send an email.
In the Power Automate flow, we’re going to use the REPLACE() function to replace all of the carriage returns in the string with an HTML line break ( <BR> ) that we can use to format the output properly.
Click to enlarge
Step 1
Initialize a new variable to hold the ‘Enter’ carriage return. The value should be just a single, lone, return.
Step 2
Make a compose step to hold the multiline text data from the CDS source
Step 3
Make a compose step with an Expression for replacing the ENTER character with the new line return.
replace(outputs('Compose_ChangeOrder_Desc'),variables('PseudoEntervariable'),'<br>')
Step 4
Use the result of the [Step 3] compose step in your later steps.