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 / Patch multiple records...
Power Apps
Unanswered

Patch multiple records in gallery using forall function

(0) ShareShare
ReportReport
Posted on by 30

Hello all,

 

In this scenario I have a user entry form to collect multiple records and display them in a gallery. I then used the patch and for all functions to write them to a SPO list. This works but instead of displaying separate records the patch function patches the same record multiple times. Any help would be much appreciated (see syntax and screenshots below).
 
ForAll(
Gallery6.AllItems,
Patch(
'CW Calendar',
Defaults('CW Calendar'),
//Below is used for patching to a lookup column, in order to patch to a choice column a table or collection needs to be made first. See the review scope combo box for more info.//
{
_UniqueKey: TextInput_EffortName.Text,
'Review Time': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Value: ComboBox_CF_RevTime.Selected.Value
},
'Review Date': DatePicker_RevDate.SelectedDate,
'Review Scope': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id: Dropdown_ScopeName.Selected.Id,
Value: Dropdown_ScopeName.Selected.Value
}
}
)
);
Refresh('CW Calendar');
Clear(CW_CalCollect)
 
Whitakc91_0-1658437370317.jpegWhitakc91_1-1658437378397.jpeg

 

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

    @Whitakc91 

    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.

     

    That said, your formula should be the following:

    Patch('CW Calendar',
     ForAll(Gallery6.AllItems,
     {
     _UniqueKey: TextInput_EffortName.Text,
     'Review Time': {Value: ComboBox_CF_RevTime.Selected.Value},
     'Review Date': DatePicker_RevDate.SelectedDate,
     'Review Scope': {Id: Dropdown_ScopeName.Selected.Id, Value: Dropdown_ScopeName.Selected.Value}
     }
     )
    )

    Not sure what your "_UniqueKey" is in this case, but in general, the unique key in your List is going to be the ID column.

     

    I hope this is helpful for you.

  • Whitakc91 Profile Picture
    30 on at

    Randy, thank you for the reply but unfortunately this did not solve my issue.

     

    I believe "_UniqueKey" is my title column which is required, I've inherited the structure of this SPO list and unfortunately it's not how I would design it given its "complexity" but it's what I have to work with.  It looks like the patch formula is only patching the last record in the collection for the number of records in the collection. I ran a monitor session and attached a screenshot since the .json filetype is not supported. I've also provided the list settings to the SPO list.

     

    2022-07-22_10-47-11.png2022-07-22_11-11-55.png

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

    @Whitakc91 

    So your issue with that column is that it is Title.  You can never rename a column in SharePoint.  It will always retain the original name. Even though you might rename in SharePoint and it will "show" that way, under the covers, it is still the same original name.  So, it is Title.

     

    PowerApps doesn't always honor name changes.  In general, it wants the real (original) name.  Some functions in PowerApps will honor the "changed" name, but it is best not to rely on them.

     

    Your Formula should be changed to:

    Patch('CW Calendar',
     ForAll(Gallery6.AllItems,
     {
     Title: TextInput_EffortName.Text,
     'Review Time': {Value: ComboBox_CF_RevTime.Selected.Value},
     'Review Date': DatePicker_RevDate.SelectedDate,
     'Review Scope': {Id: Dropdown_ScopeName.Selected.Id, Value: Dropdown_ScopeName.Selected.Value}
     }
     )
    )

    (Assuming that none of the other field names above have been changed.  If so, then change them to the original names)

     

    Next.  The table creation (the ForAll) function in the above formula will return a table of all the records in Gallery6.

    The bigger question is, are all of the controls referenced in the record schema (i.e. TextInput_EffortName, Combox_CF_RevTime, etc.) all in the Gallery6 template?  If so, then you should be getting all of those in the table properly and the above formula should be creating a record for each item in the gallery.

     

    You mention in your reply "collection" - the above (and suggested formula) does not use a collection.  So what are you referring to?

     

  • Whitakc91 Profile Picture
    30 on at

    Thanks for the assistance @RandyHayes upon further review I realized was approaching this issue incorrectly and should have just been patching my collection instead of the records in a gallery whose purpose is to display the contents of my collection. Sorry for the confusion I think I was getting tunnel vision after staring at this issue for so long.

     

    My new formula looks like:

     

    ForAll(
     CW_CalCollect,
     Patch(
     'CW Calendar',
     Defaults('CW Calendar'),
     {
     Title: Effort_Name,
     'Review Time': {Value: Review_x0020_Time},
     'Review Date': Review_Date,
     'Review Scope': {Id:Id, Value: Review_Scope
     }}
     )
    );
    Refresh('CW Calendar');
    Clear(CW_CalCollect)

     

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

    @Whitakc91 

    The ForAll is still being used incorrectly and performance will suffer tremendously from it.

    Also, there is no need to refresh your list.  The list in the app will already have all the updates.  The Refresh just slows down things even more for nothing.

     

    Please consider changing your Formula to the following:

    Patch(
     'CW Calendar',
     ForAll(CW_CalCollect,
     {
     Title: Effort_Name,
     'Review Time': {Value: Review_x0020_Time},
     'Review Date': Review_Date,
     'Review Scope': {Id:Id, Value: Review_Scope
     }
     )
    );
    Clear(CW_CalCollect)

     

    If the gallery is JUST for display of a collection, then the above is fine, but if you are doing any interaction in the gallery, you should be going from the Gallery, not the collection.

  • Whitakc91 Profile Picture
    30 on at

    Currently it's just a display but I would like to add a button in the gallery to remove the selected record from the collection.

  • dupreti131991 Profile Picture
    2 on at

    "I am working on an Excel grid application in Power Apps. The app contains multiple columns and rows. Users have the ability to update columns using dropdown values and text inputs. After these updates, I intend to patch the records in SharePoint."

    please help in this code.  I am using below code. It is patching same against in each row. 

    ForAll(
    sel,
    Patch(
    'Interviewer List',
    LookUp(
    'Interviewer List',
    ID = Value(Label1.Text)
    ),
    {
    Dislikes: Dropdown1.Selected.Value,
    Comments: TextInput2.Text
    }
    )
    );

     

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 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard