cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
WiggityZwiggity
Helper V
Helper V

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)

 

Example:

 

URL to modify: https://rentreadyorders.typeform.com/to/e7aKoF?market=xxxxx&name=xxxxx&id=xxxxx (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

 

 

 

 

12 REPLIES 12

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

LongStoryShort.PNG

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

replace(variables('longstory'),variables('Long'),variables('Short'))

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.

v-xida-msft
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:

https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

 

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 (https://rentreadyorders.typeform.com/to/e7aKoF?market=xxxxx&name=xxxxx&id=xxxxx) with a specific Dynamic content from "Get items" action, please take a try with the following formula within Compose action as below:

 

replace(outputs('RAW_URL'),'market=xxxxx',item()?['Product_x0020_Area'])

 

 

5.JPG

 

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:

replace(outputs('RAW_URL'),'market=xxxxx',item()?['ColumnNameOfYourSharePointList'])

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:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

 

 

Best regards,

Kris

 

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.
eliotcole
Impactful Individual
Impactful Individual

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.
      Clipboard01.jpg
    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.
      Clipboard02.jpg

 

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

 

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 !

eliotcole
Impactful Individual
Impactful Individual

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:

PowerDylan_3-1595366645040.png

 

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:

PowerDylan_1-1595366432284.png

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',' ')

PowerDylan_2-1595366554128.png

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 https://powerusers.microsoft.com/t5/Building-Flows/Replace-Newline-in-Flow-Expression/m-p/448574#M53...:

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:
concat(uriComponentToString('%0D'),uriComponentToString('%0A'))
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.

 

eliotcole
Impactful Individual
Impactful Individual

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

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (870)