web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll patch patches a...
Power Apps
Answered

ForAll patch patches all columns with the same data

(0) ShareShare
ReportReport
Posted on by 15

Hi, I hope someone can help me with this, I have a gallery with a label and textbox, I want to patch what the user writes in the textbox to the dataverse but whenever I use a forAll it only sends through the data put in the last text box into all the columns in the dataverse. I tried to make my code as simple as possible so here it is: 

Harry1_0-1640022668921.png

Any help would be appreciated!

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Harry1 

    Your ForAll is backwards.  ForAll is a function that returns a table of records.  It is not a For/Loop like in a development platform.  Although it can be forced to mimic a development function, performance will suffer.

    Also, do not issue a Refresh after you do this function...there is no need as it will already have the correct new information in the datasource in your app.  It only causes more performance issues.

     

    Your formula should be:

    Patch('Survey Q&AS',
     ForAll(UserQuestionsGallery.AllItems As _item,
     {ID: _item.ID,
     'User Answer': _item.TextBox5.Text
     }
     )
    )

     

    The mystery though was that you have a TextBox5 control and are specifying .Value on it...That is not a TextBox property.  If this is some other type of control, just named that way, then correct as needed.

     

    I hope this is helpful for you.

     

  • Harry1 Profile Picture
    15 on at

    Thanks for replying but I don't understand the logic behind your code, nor does it work in my system.

    By my understanding the Patch function works by putting in three arguments a source, a record and an update, but yours only provides two and the second is a table not a record so I'm unsure how it is meant to work.

     

     You say that the ForAll function does not work like a for loop but that seems to be how it is described in the documentation: "The ForAll function evaluates a formula for all the records in a table." and I have also used it as such in other apps.

     

    Also the reason I have used .Value on the textbox is because this app is a custom page so I have used the custom page textbox which has slightly different methods.

     

    Edit:

    As you suggested I got it to work with:

    Harry1_0-1640089734653.png

    The reason it was not working earlier was because the textbox was inside a container, that is why it wasn't being referenced correctly, thanks for your help

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @Harry1 

    Take a look over the documentation on Patch.  Patch is a universal function that can take various parameters.

    One of those is to use what they call a BaseTable parameter - which is a table of records to patch.

    Patch is magical in that the ONLY thing you need for it to determine what to do is the primary key of your datasource.  If you provide one, it will find that record and modify it.  If you don't it will create a new record.

     

    The drawback to using a ForAll like a ForLoop is that the intention of it is to return a table that contains records based on formulas evaluated for each iteration of the supplied table (parameter 1) and create records from the provided formula/record (parameter 2).  If you look at the docs on ForAll, you will see this stated in the Return Value section.

    And although the ForAll can be used as a sort-of ForLoop, it was not its intended purpose (thus why you cannot just supply anything you want in the second parameter - such as setting variables.)

     

    Since PowerApps is not a development environment, programming principles like ForLoop and such are not really applicable here.  It is a platform that lets you design formulas to provide values for what you are intending to do.  It is modeled after Excel.

     

    But to sum...the ForAll being used to do in internal patch will be much less performant than simply having the ForAll supply a table of records to work with.

    Also, consider that each function in your ForLoop will have values returned.  i.e. Patch returns a record of the Patched record. ALL of that is going into a Table as a result of the ForAll.  So, it is building a table with returned results that ultimately goes no where when used as a ForLoop...so it is wasted.  (this is also mentioned in the docs under the taking action section).

    Again, doing that will cause the entire process to take much more time and consume more memory in the process.

     

    Also, for performance purposes...look at other functions you might use - like Remove - it also works much better when supplied a table and not used in a reversed ForAll.

     

    Hopefully this is clear and helpful for you.  And...glad you got the other one working!

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard