Showing results for 
Search instead for 
Did you mean: 

Use Dynamic Content in Replace Expression

I am trying to replace specific sections of a url by using the replace function.  My intent is to replace components of the url utilizing retrieved values from a SharePoint List in a for each loop.  The dynamic content I want to utilize is not available from the list when composing the replace expression for some reason so I have used a compose action to capture the information I need to later insert in the replace expression but I am unsure of how to structure the expression (I keep getting an invalid expression)




URL to modify: (I use a compose to capture this)


Replace with text: replace(outputs('RAW_URL'),'market=xxxxx','market=tri')


Replace with dyanmic content is what I dont understand: replace(outputs('RAW_URL'),'market=xxxxx','outputs('ID)') doesn't work for example.


Picture of flow attached.  Ideally I would like to just directly insert the dynamic content - not sure why it isn't available when using the replace function but it is otherwise available.  Secondarily if that does not work - what is the correct syntax for using the output from the previous step to insert it into the replace expression?Dynamic values from SharePoint List Get Items action appearing in a generic compose actionDynamic values from SharePoint List Get Items action appearing in a generic compose actionSame SharePoint List dynamic content not available in a replace expressionSame SharePoint List dynamic content not available in a replace expression






The easiest way to do this is by typeing the expression  e..g replace()   

Then move you cursor in between the brackets. Then click on dynamic content and add what you want.

Thanks @Pieter_Veenstra I understand how to insert dynamic content into the expression, in the example provided I am already using dynamic content in the initial string that the replace expression is utlizing, however I am unable to utilize dynamic content as the replacement in the structure of replace(string,'string to replace','string replacing')

The other issue I have is that when I try to insert dynamic content into an expression the dynamic content "dissapears" See below:No expression - full dynamic content available from list queryNo expression - full dynamic content available from list querysimple expression string() in expression, no dynamic content from the list querry availablesimple expression string() in expression, no dynamic content from the list querry available


This  flow worked for me. the variable 4 is set to : 


Thanks @Pieter_Veenstra that works but I have never been forced to use variables before, I could always do it by directly utilizing an expression in a compose action vs initiliazing and setting a variable.  Does anyone know if this behavior has recently changed?  I also am very perplexed as to why dynamic content is not available to me directly when writing certain expressions.

Community Support
Community Support

Hi @WiggityZwiggity,


The issue is conformed on my side, we could not reference Dynamic contents from "Get items" action of SharePoint connector within replace expression currently.


If you would like this feature to be added in Microsoft Flow, please submit an idea to Flow Ideas Forum:


In addition, if you want to reference the Dynamic contents from "Get items" action, you could consider take a try to write WDL expression to get the specific Dynamic content from the "Get items" action. I assume that you want to replace the 'market=xxxxx' text within your RAW URL ( with a specific Dynamic content from "Get items" action, please take a try with the following formula within Compose action as below:







Note: The Product Area (shows up as Product_x0020_Area within replace expression) is a column in my SharePoint list, on your side, you should type the following formula within "Compose" action:


If there is a space within your column name, please replace the space with '_x0020_' within the replace expression.



More details about WDL expression within Microsoft Flow, please check the following article:



Best regards,



Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, @WiggityZwiggity , the work around I use to win (!!!!) against this highly irritating nonsense is to put what I need openly somewhere else in a compose action, then cut it out from there, and paste it into the expression.


This way I win, and the computer doesn't beat me again, haha!


Of course, you'll need to remov... ah, here's what I'm trying to say. Let's say I've made a variable, "test", that because power automate is having it's regular hissy fit, won't let in the expression. I perform the following:

    1. Insert the dynamic data (the variable in this case) as an element in a Compose box.
    2. Then I cut that from the Compose, and start writing my expression.
    3. Once in the expression, I use CTRL+V and paste the dynamic data (my variable) in to it.


    1. I remove the "@{" from the beginning and "}" from the end of the pasted text.


Now I can continue with my flow!


Appreciate that this is maybe a year or two later, but hope that this helps others, if not yourself.

does not work,

this NEEDS to be fixed !

Hey, @DragonLord , what about it doesn't work, mate? Perhaps I can help make this easier ... I've just been doing it in a flow.

Hi @eliotcole,

your technique worked for me, but unfortunately still hasn't solved the challenge I'm trying to crack:



In the Power Automate Flow above, I'm trying to read rows in from an Excel spreadsheet, which I then am trying to replace the line break characters \n with a space (removing the line breaks).  When I analyze my flow, I can see that the line breaks are being read in:


but unfortunately, the Compose (in the first screenshot's tooltip) I've created an expression to replace all '\n' with ' ', doesn't seem to "see" the line breaks: 

replace(items('Apply_to_each')?['testColumn'],'\n',' ')


Any ideas?

Good news! After several hours of crawling forums, I managed to piece together a solution to my problem. I wanted to share it here in case others are having the same issue:

first I managed to find a (relatively simple) solution to replacing the /n line breaks by themselves in @DennisKuhn1's solution to

first I initialized a new variable


which just has a single press of the Enter key in the Value field.  Then later in the Apply to each section of my workflow, I updated the expression in the Compose action to: 

replace(items('Apply_to_each')?['testColumn'],variables('newLine'),' ')
Unfortunately, the REAL problem I had been trying to solve was that the Excel file that I was using was actually inserting a Carriage Return (\r) followed by a New Line (\n)... this was a bit more convoluted.
Similar to above, I initialized a string variable called newLine, but this time I put the expression:
in for the Value.  This creates a Carriage Return character followed by a New Line character which then worked with the same replace function used above.


Glad that you got it sorted, @PowerDylan , sorry I came back late to this.


If I have a text string that has multiple lines that I need to parse, then my work around will almost always be (again, perhaps over-complicating) to set each line as its own entity (object?) in an array. Then they can be handled separately, as required.


I'll do that using the split expression on a newline variable (like yours), then process each array item in an Apply to each action. This way (as said) I can apply any text working that needs to be done to each line individually, then, if I do need them back as a single string with line breaks I can always join them back up.


I tend to prefer to play all my logic for things like this out in the flow, because whilst it would still work to squidge it all into a single expression or two ... that will possibly make the next person to handle my flow not really understand what's going on. And I always try to sell Power Automate as the easiest thing in the world, so I'm big on commenting, renaming, and playing out most (not all) of my logic.

Helpful resources

Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (3,735)