cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User
Super User

Ignore - figured it out! Apply To Each, Set Variable - Only the last Set Variable persists

Please ignore - user error! I wasn't passing the variable into the replace function, I was passing the original HTML each time. Is there a way to delete posts to save my embarrassment?!?!

 

Hi

 

Scenario: I create an HTML table in Flow. I want to replace several tags (<table>, <thead>,<td>) with versions that contain style information (e.g. replace <td> with <td Style = " border: 1px solid #ddd; padding: 8px;">). 

 

Flow: I have made a table in Excel with a column for the Tag (Element) and one for the Replacement Tag (Replacement). I initialize a string variable (strFormattedHTML) and populate it with the HTML table. I then have an 'Apply to each' which iterates through the rows of the Excel table and performs a 'Set Variable' step where I replace Element with Replacement as follows:

 

replace(body('Create_HTML_table'),items('Apply_to_each')?['Element'],items('Apply_to_each')?['Replacement'])

On the first pass of the loop, <table> should be replaced with <table Style =.... and then stored in the variable. On the next loop, <thead> should be replaced and so on, so at the end of the loop, the variable reflects all the replacements.

 

Issue: Every time the Set Variable step fires, it is using the initial value of strFormattedHTML, not the value from the prior iteration of the Apply To Each loop, so only the final replacement is reflected in the value of strFormattedHTML. When I check the Run History and step through the iterations of th eloop, I can see that each iteration of the loop performed exactly as expected, but the new value of strFormattedHTML is not being persisted.

 

Question: How can I update a variable to a new value for each iteration of an Apply To Each loop and then use the new value in the subsequent iteration?

 

Thanks

Paul

0 REPLIES 0

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (2,182)