cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

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

@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.

@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

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Results posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Top Solution Authors
Top Kudoed Authors
Users online (4,638)