cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lmheimendinger
Resolver III
Resolver III

Patch in Forall failing to update

I have been wrestling with trying to update a collection.  Let me describe the problem I am trying to solve.

 

I have a SharePoint list that has one record corresponding to some buttons that I will use in various Power Apps.  Based on user shared access to other Power Apps - each button corresponds to a different app - I want to update NOT THE LIST but a collection created from the list.  Why? Because multiple logons for the same or differnt apps that use the list could run at the same time.

 

Here's what I do:

 

  1. ClearCollect(col1, SharePoit list) - get list into collection
  2. ClearCollect(col2, coll1) - get a copy to use in ForAll
  3. ClearCollect(colSeq,Sequence(CountRows(col1))) - get a sequence of integers 1 to number of rows in list
  4. Set(varSeq, Sequence(CountRows(colNavigate))) - variable as an array

In the list and col1 and col2, the IDs all start at 1 and increase by 1 for all rows, so the ID matches the sequence array.  There is also another column for the list and collections called ButtonID which is an integer that corresponds to the ID (but is just a number column with 0 decimal places).  The reason for the sequence, I thought, was that in the ForAll I could by trimming the first row of the array it would always match the collection row in ForAll.  Apparantly that works as in testing I create an array row containng the sequence number and buttonid and they match.

Here is then what I try to do:

ForAll(col1,
   Patch(col2, LookUp(col2,ThisRecord.Title=Title, {UserOK:TestPermissions.Run(varUser,'App ID').result}));
   Remove(colSeq,First(colSeq))
)

The Power Automate is a flow that tests each app ID passed to it (in the SharePoint list and collections) and returns a "Yes" or "No" text to indicate if the user has shared permissions for that app.  I can look at the run history for that flow and see that it is successful and returns the desired value for each row in the list.  But the collection never gets updated.

 

I have tried other values in LookUp() all of which were equally unsuccessful, such as ID=ID or Title=Title or ButtonID=ButtonID.  I thought ID=First(colSeq).Value would be the thing I actually want but get  a type mismatch of Number = Table.

 

Why do this?  I want a gallery to have a list of allowable buttons displayed (along with other data), so filtering the gallery toonly include UserOK = "Yes" makes this a snap if I can figure out how to update the collection for the gallery.....

 

I realize I am probably doing something stupod, but what?

 

3 REPLIES 3
RandyHayes
Super User
Super User

@lmheimendinger 

To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not.  ForAll is a function that returns a table of records based on your iteration table and record schema.

It is more efficient to use the function as intended and will provide better performance.

 

Also, trying to look at the For All as a ForLoop is causing you to chase your tail trying to make it work like one...as I am guessing you are feeling at this point be trying this and that to deal with so many duplicates of collection tables and trying to index it with another.

 

My first suggestion beyond that is to modify your flow to accept a list of apps rather than just a single app.  The reason for that is, most ALL function in PowerApps accept tables as parameters (ie. Patch in this case).  If you have a flow that only handles a single record, then you are forced to use the ForAll backward and then the flow has to be instantiated over and over again.  This is excessive use of your flows and also a performance hog!

 

Not entirely understanding your source data and the need for sequences and ID's that match the existing ID, but without that your formula can be changed to:

ClearCollect(colAppList,
    ForAll(SharePointList,
        {
        Title: Title,
        'App ID': 'App ID',
        UserOK: TestPermissions.Run(varUser,'App ID').result
        }
     )
)

This would provide a collection (in memory database table) of the list apps and the permissions for the users.

 

If you are not planning to alter the records in memory in your app, then you can skip the collection and just assign to a variable:

Set(glbAppList,
    ForAll(SharePointList,
        {
        Title: Title,
        'App ID': 'App ID',
        UserOK: TestPermissions.Run(varUser,'App ID').result
        }
     )
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

A lot to parse but thanks and I will advise on progress or failures.  

 

Question: in the Set(gblAppList,....) sugesstion, that should result in an array, right?  I still have the problem of using the results to filter the gallery.

 

Question:  what exactly do you mean by "backwards" use of ForAll?  Am I incorrect to believe that as I have used it, it iterates though col1 (which is identical to col2) but the Patch operates on col2 as a corresponding row?  I know I can't Patcvh col1 in the ForAll which is why I duplicated it in col2.

RandyHayes
Super User
Super User

@lmheimendinger 

When you say array...there really is not that in PowerApps...it is a table.  And so yes, glbAppList would be a table.  Tables can be in variables.  Those tables can be used on any component that needs a table (like your gallery).

 

Oh the ForAll - one of my favorite functions in PowerApps (when used properly) as it is the most powerful data tools in the arsenal of functions!

 

ForAll is a function that returns a table.  The structure is ForAll(table, {record definition})  So the table is the table that ForAll will iterate over, the record definition defines what the schema of the returned table will be.

Example:

ForAll(Sequence(10), {MyCol: Value + 5})

In the above, the table to iterate over is a table (returned from Sequence) that has a single column called Value.  We want our ForAll to iterate over that and create a table with records that have a MyCol column that contains the Value of the Sequence-returned table plus 5.  

 

One very important thing to keep in mind is that if you do NOT specify a record structure, PowerApps will automatically create a Value column.

So, for example:  ["a", "b", "c"]  will produce a table with a single column called Value (because nothing was specified.  It is equivalent to:  Table({Value: "a"}, {Value: "b"}, {Value: "c"})  (but you can see the shorthand is quicker if you are good with a Value column)

 

Likewise, if you use a ForAll with no record definition - ex: ForAll(["a", "b", "c"], "X") This will produce a table with three rows that have a single column called Value with a value of "X"

 

Why I say that is...when you use the ForAll backward, it is still creating a table, you just are wasting the output of it.

It's like putting a 2+2 in an action formula...PowerApps will still evaluate it to 4, but since you are not assigning it or using it...it is wasted.

 

When trying to use ForAll as a ForLoop (which it will mimic because it technically iterates over things), you will quickly come to hate it because that is not what it was designed for.  You cannot do things in it like in a ForLoop because (hopefully now obvious) you can't impact the source iterator while you iterate over it.  Plus, if you are putting "statements" in your ForAll rather than record information, then each is returning values that are being added to a Value column in the ForAll record...and then wasted!  This ALL contributes to added and unnecessary overhead in your app.

 

I just wish that they would modify the docs on PowerApps to NOT have examples that use the ForAll backward!  It gives people the WRONG impression on how to use it.  And since many developers flock to PowerApps with the developer mindset...the first thing they are looking for is "where's the for loop function?" - They find the ForAll and think "That's it!".  Quickly things go wrong!

 

But the biggest obstacle is the collections and the duplication of collections.   Keep in mind that each one is just a copy of the data over and over.  There is no need for all that overhead in the app.

A collection should ONLY be used in scenarios where you need to add/remove or update records in a table in memory. (or if you are building an offline app...where you do need in-memory database ability).  

 

You'll see that the last formula I provided uses no collections.  It produces a table of records (you can see the records structure in the ForAll) into a table that is stored in a variable (because it most likely does not need to be add/remove/updated later on in the app).  

 

Hopefully this all makes sense and is helpful for you.  I can go on and on about ForAll usage and Collection usage in PowerApps because they are probably one of the top two things that are misused in the platform and contribute to people doing much more work than is necessary in their design process.

 

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements

Power Platform Connections Ep 14 | J. Panchal | Thursday, 18 May 2023

Episode Fourteen of Power Platform Connections sees David Warner and Hugo Bernier talk to Microsoft PM Jocelyn Panchal, alongside the latest news, videos, product reviews, and community blogs.   Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show.      Show schedule in this episode:  00:00 Cold Open 00:32 Show Intro 01:10 Jocelyn Panchal Interview 24:10 Blogs & Articles 29:50 Outro & Bloopers  Check out the blogs and articles featured in this week’s episode:   https://www.nathalieleenders.com/Blog/index.php/;focus=STRATP_com_cm4all_wdn_Flatpress_42136159&path=?x=entry:entry230511-101930#C_STRATP_com_cm4all_wdn_Flatpress_42136159__-anchor  @NathLeenders https://www.keithatherton.com/posts/2023-05-12-msbuild2023-cloud-skills-challenge/  @MrKeithAtherton https://elliskarim.com/2023/05/13/how-to-find-files-in-onedrive-that-match-a-naming-pattern/  @MrCaptainKarim https://www.linkedin.com/pulse/my-fond-memories-scottish-summit-2022-pranav-khurana/ @pranavkhuranauk https://www.linkedin.com/feed/update/urn:li:activity:7061777660745560064/?updateEntityUrn=urn%3Ali%3Afs_feedUpdate%3A%28V2%2Curn%3Ali%3Aactivity%3A7061777660745560064%29  @thevictordantas  Action requested: Feel free to provide feedback on how we can make our community more inclusive and diverse.  This episode premiered live on our YouTube at 12pm PST on Thursday 18th May 2023.  Video series available at Power Platform Community YouTube channel.  Upcoming events:  Power Apps Developers Summit – May 19-20th - London European Power Platform conference – Jun. 20-22nd - Dublin Microsoft Power Platform Conference – Oct. 3-5th - Las Vegas  Join our Communities:  Power Apps Community Power Automate Community Power Virtual Agents Community Power Pages Community  If you’d like to hear from a specific community member in an upcoming recording and/or have specific questions for the Power Platform Connections team, please let us know. We will do our best to address all your requests or questions.   

May 2023 Community Newsletter and Upcoming Events

Welcome to our May 2023 Community Newsletter, where we'll be highlighting the latest news, releases, upcoming events, and the great work of our members inside the Biz Apps communities. If you're new to this LinkedIn group, be sure to subscribe here in the News & Announcements to stay up to date with the latest news from our ever-growing membership network who "changed the way they thought about code".       LATEST NEWS "Mondays at Microsoft" LIVE on LinkedIn - 8am PST - Monday 15th May  - Grab your Monday morning coffee and come join Principal Program Managers Heather Cook and Karuana Gatimu for the premiere episode of "Mondays at Microsoft"! This show will kick off the launch of the new Microsoft Community LinkedIn channel and cover a whole host of hot topics from across the #PowerPlatform, #ModernWork, #Dynamics365, #AI, and everything in-between. Just click the image below to register and come join the team LIVE on Monday 15th May 2023 at 8am PST. Hope to see you there!     Executive Keynote | Microsoft Customer Success Day CVP for Business Applications & Platform, Charles Lamanna, shares the latest #BusinessApplications product enhancements and updates to help customers achieve their business outcomes.     S01E13 Power Platform Connections - 12pm PST - Thursday 11th May Episode Thirteen of Power Platform Connections sees Hugo Bernier take a deep dive into the mind of co-host David Warner II, alongside the reviewing the great work of Dennis Goedegebuure, Keith Atherton, Michael Megel, Cat Schneider, and more. Click below to subscribe and get notified, with David and Hugo LIVE in the YouTube chat from 12pm PST. And use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show.     UPCOMING EVENTS   European Power Platform Conference - early bird ticket sale ends! The European Power Platform Conference early bird ticket sale ends on Friday 12th May 2023! #EPPC23 brings together the Microsoft Power Platform Communities for three days of unrivaled days in-person learning, connections and inspiration, featuring three inspirational keynotes, six expert full-day tutorials, and over eighty-five specialist sessions, with guest speakers including April Dunnam, Dona Sarkar, Ilya Fainberg, Janet Robb, Daniel Laskewitz, Rui Santos, Jens Christian Schrøder, Marco Rocca, and many more. Deep dive into the latest product advancements as you hear from some of the brightest minds in the #PowerApps space. Click here to book your ticket today and save!      DynamicMinds Conference - Slovenia - 22-24th May 2023 It's not long now until the DynamicsMinds Conference, which takes place in Slovenia on 22nd - 24th May, 2023 - where brilliant minds meet, mingle & share! This great Power Platform and Dynamics 365 Conference features a whole host of amazing speakers, including the likes of Georg Glantschnig, Dona Sarkar, Tommy Skaue, Monique Hayward, Aleksandar Totovic, Rachel Profitt, Aurélien CLERE, Ana Inés Urrutia de Souza, Luca Pellegrini, Bostjan Golob, Shannon Mullins, Elena Baeva, Ivan Ficko, Guro Faller, Vivian Voss, Andrew Bibby, Tricia Sinclair, Roger Gilchrist, Sara Lagerquist, Steve Mordue, and many more. Click here: DynamicsMinds Conference for more info on what is sure an amazing community conference covering all aspects of Power Platform and beyond.    Days of Knowledge Conference in Denmark - 1-2nd June 2023 Check out 'Days of Knowledge', a Directions 4 Partners conference on 1st-2nd June in Odense, Denmark, which focuses on educating employees, sharing knowledge and upgrading Business Central professionals. This fantastic two-day conference offers a combination of training sessions and workshops - all with Business Central and related products as the main topic. There's a great list of industry experts sharing their knowledge, including Iona V., Bert Verbeek, Liza Juhlin, Douglas Romão, Carolina Edvinsson, Kim Dalsgaard Christensen, Inga Sartauskaite, Peik Bech-Andersen, Shannon Mullins, James Crowter, Mona Borksted Nielsen, Renato Fajdiga, Vivian Voss, Sven Noomen, Paulien Buskens, Andri Már Helgason, Kayleen Hannigan, Freddy Kristiansen, Signe Agerbo, Luc van Vugt, and many more. If you want to meet industry experts, gain an advantage in the SMB-market, and acquire new knowledge about Microsoft Dynamics Business Central, click here Days of Knowledge Conference in Denmark to buy your ticket today!   COMMUNITY HIGHLIGHTS Check out our top Super and Community Users reaching new levels! These hardworking members are posting, answering questions, kudos, and providing top solutions in their communities.   Power Apps:  Super Users: @WarrenBelz, @LaurensM  @BCBuizer  Community Users:  @Amik@ @mmollet, @Cr1t    Power Automate:  Super Users: @Expiscornovus , @grantjenkins, @abm  Community Users: @Nived_Nambiar, @ManishSolanki    Power Virtual Agents:  Super Users: @Pstork1, @Expiscornovus  Community Users: @JoseA, @fernandosilva, @angerfire1213    Power Pages: Super Users: @ragavanrajan  Community Users: @Fubar, @Madhankumar_L,@gospa  LATEST COMMUNITY BLOG ARTICLES  Power Apps Community Blog  Power Automate Community Blog  Power Virtual Agents Community Blog  Power Pages Community Blog  Check out 'Using the Community' for more helpful tips and information:  Power Apps , Power Automate, Power Virtual Agents, Power Pages 

Microsoft Power Platform Conference | Registration Open | Oct. 3-5 2023

We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5 2023! But first, let's take a look back at some fun moments and the best community in tech from MPPC 2022 in Orlando, Florida.   Featuring guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, Stephen Siciliano, Hugo Bernier and many more.   Register today: https://www.powerplatformconf.com/   

Check out the new Power Platform Communities Front Door Experience!

We are excited to share the ‘Power Platform Communities Front Door’ experience with you!   Front Door brings together content from all the Power Platform communities into a single place for our community members, customers and low-code, no-code enthusiasts to learn, share and engage with peers, advocates, community program managers and our product team members. There are a host of features and new capabilities now available on Power Platform Communities Front Door to make content more discoverable for all power product community users which includes ForumsUser GroupsEventsCommunity highlightsCommunity by numbersLinks to all communities Users can see top discussions from across all the Power Platform communities and easily navigate to the latest or trending posts for further interaction. Additionally, they can filter to individual products as well.       Users can filter and browse the user group events from all power platform products with feature parity to existing community user group experience and added filtering capabilities.     Users can now explore user groups on the Power Platform Front Door landing page with capability to view all products in Power Platform.    Explore Power Platform Communities Front Door today. Visit Power Platform Community Front door to easily navigate to the different product communities, view a roll up of user groups, events and forums.

Welcome to the Power Apps Community

Welcome! Congratulations on joining the Microsoft Power Apps community! You are now a part of a vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun! Now that you are a member, you can enjoy the following resources:   The Microsoft Power Apps Community Forums If you are looking for support with any part of Microsoft Power Apps, our forums are the place to go. They are titled "Get Help with Microsoft Power Apps " and there you will find thousands of technical professionals with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Apps community forums! Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered!   Microsoft Power Apps IdeasDo you have an idea to improve the Microsoft Power Apps experience, or a feature request for future product updates? Then the "Power Apps Ideas" section is where you can contribute your suggestions and vote for ideas posted by other community members. We constantly look to the most voted Ideas when planning updates, so your suggestions and votes will always make a difference.   Community Blog & NewsOver the years, more than 600 Power Apps Community Blog Articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on building Power Apps. On the Power Apps Community Blog, read the latest Power Apps related posts from our community blog authors around the world. Let us know if you would like to become an author and contribute your own writing — everything Power Apps related is welcome!   Power Apps Samples, Learning and Videos GalleriesOur galleries have a little bit of everything to do with Power Apps. Our galleries are great for finding inspiration for your next app or component. You can view, comment and kudo the apps and component gallery to see what others have created! Or share Power Apps that you have created with other Power Apps enthusiasts. Along with all of that awesome content, there is the Power Apps Community Video & MBAS gallery where you can watch tutorials and demos by Microsoft staff, partners, and community gurus in our community video gallery.   Again, we are excited to welcome you to the Microsoft Power Apps community family! Whether you are brand new to the world of process automation or you are a seasoned Power Apps veteran. Our goal is to shape the community to be your ‘go to’ for support, networking, education, inspiration and encouragement as we enjoy this adventure together!   Let us know in the Community Feedback if you have any questions or comments about your community experience.To learn more about the community and your account be sure to visit our Community Support Area boards to learn more! We look forward to seeing you in the Power Apps Community!The Power Apps Team

Top Solution Authors
Top Kudoed Authors
Users online (3,825)