cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Commander
Kudo Commander

Building a string within ForAll

I have an approval flow and I would like to display information within the approval. I have a sharepoint list full of data and I need to display each row of data in the approval flow. Ideally I would use Set() inside of ForAll() in order to build a string of the data I need and format it, but you cannot use Set() inside of ForAll()

 

Any ideas? Has anyone else had a similar dillema before?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Building a string within ForAll

Hi @pcaracc

 

One way to work around this problem is to Collect your data into a temporary collection inside your call to the ForAll function. You can then combine the rows with the Concat function to derive your complete string.

The post that I answered here uses this exact technique. Hopefully, you'll get the gist of the formula that you would use.

https://powerusers.microsoft.com/t5/Creating-Apps/Send-email-HTML-format-problem/m-p/121482#M2649

The reason why the ForAll function doesn't support the Set function is because PowerApps can execute the iterations of a ForAll loop in parallel. There's no guarantee that PowerApps will loop over the source records in order, therefore, you might need to Collect a sort value to enable you to Concat your final string in the correct sequence.

View solution in original post

8 REPLIES 8
Highlighted
Super User
Super User

Re: Building a string within ForAll

Hi @pcaracc

 

One way to work around this problem is to Collect your data into a temporary collection inside your call to the ForAll function. You can then combine the rows with the Concat function to derive your complete string.

The post that I answered here uses this exact technique. Hopefully, you'll get the gist of the formula that you would use.

https://powerusers.microsoft.com/t5/Creating-Apps/Send-email-HTML-format-problem/m-p/121482#M2649

The reason why the ForAll function doesn't support the Set function is because PowerApps can execute the iterations of a ForAll loop in parallel. There's no guarantee that PowerApps will loop over the source records in order, therefore, you might need to Collect a sort value to enable you to Concat your final string in the correct sequence.

View solution in original post

Highlighted
Kudo Commander
Kudo Commander

Re: Building a string within ForAll

Thank you @timl 

 

This solution worked very well. It would be nice to see a non concurrent ForAll implementation in the future.

Highlighted
Post Patron
Post Patron

Re: Building a string within ForAll

I have this exact same need, but am unable to look at your solution in the other post.    Is there any way you can share it here or is there another place it can be accessed?

 

@timl

Highlighted
Super User
Super User

Re: Building a string within ForAll

@JR-BejeweledOne 

Google Cache is your best friend in this situation...

https://webcache.googleusercontent.com/search?q=cache:w2q7bAhHsg4J:https://powerusers.microsoft.com/...

 

I just typed this text string into Google

 

powerusers 121482#M2649

And looked at the Cached webpage instead

Highlighted
Post Patron
Post Patron

Re: Building a string within ForAll

I get the exact same error I get when trying to go to it from the link.  

 

 

 

Highlighted
Super User
Super User

Re: Building a string within ForAll

That's a pain that my original post no longer exists 😞

To summarise the technique, suppose you have a collection that looks like this and you want to convert this to an HTML table.

image.png

 

Here's the code to generate a table of results.

Collect(outputTable,"<Table>");
ForAll(Countries,
Collect(outputTable, "<tr><td>" & name & "</td></tr>")
); Collect(outputTable,"</Table>")

The result of this looks like this:

 

image.png

 

In an HTML control, you can then combine all of these rows into a single string with this:

Concat(outputTable, Value)

Hope that helps.

 

Post Patron
Post Patron

Re: Building a string within ForAll

Thank you for this.   Can you show me what the 'ForAll' line in the code would look like if I have a collection similar to below and I wanted to concat the Holiday and date together so the end result string would look like this:

  Christmas Eve   12/24/2019

  Christmas Day  12/25/2019

 

Collection.jpg

Highlighted
Super User
Super User

Re: Building a string within ForAll

Hi @JR-BejeweledOne 

The formula would look like this:

Collect(outputTable,"<Table>");
ForAll(YourCollectionName,
       Collect(outputTable, "<tr><td>" & Name & "</td><td>" & Text(StartDate) & "</td></tr>")
);
Collect(outputTable,"</Table>")

 

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Robotic Process Automation

Let's talk about the solution provided by Microsoft for Robotic Process Automation (RPA)

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

Top Solution Authors
Top Kudoed Authors
Users online (8,328)