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 Apps
Unanswered

Patch Collection

(0) ShareShare
ReportReport
Posted on by

i have collection(selected records from Gallery) in powerapps which contains 20 coloumn, now i want to patch few coloumns from collection to Sharepoint list. how to patch the code?

Categories:
I have the same question (0)
  • madlad Profile Picture
    2,637 Moderator on at

    I'm assuming your SharePoint list and collection are set up similarly. To patch items from a collection as new items, you could try something along the lines of

    ForAll(
     *YourCollection*,
     Patch(
     *YourSPList*,
     Defaults(*YourSPList*),
     {
     Value1: ThisRecord.Value1,
     Value2: ThisRecord.Value2,
     Ect.
     }
     )
    )

     To update records instead of creating new ones, specify the record to update instead of using Defaults(YourSPList) in your patch statement. 

     

    For more info on Patch, see The Documentation

     

    Hope this helps!

  • venky232 Profile Picture
    on at

    its working but if collection is empty and when user click submit button , it is creating empty record in SP list. how to avoid this?

  • madlad Profile Picture
    2,637 Moderator on at

    Try something like:

    If(
     !IsEmpty(*YourCollection*),
     Patch(...)
    )
  • venky232 Profile Picture
    on at
    ForAll(
        MyCollection,
        If(
            !IsEmpty(MyCollection),
            Patch(
                'ABC',
                Defaults('ABC'),
                {
                    Title: ThisRecord.'Title'
                })))

    still showing empty record in SP list
         
  • madlad Profile Picture
    2,637 Moderator on at

    Try:

    If(
     !IsEmpty(MyCollection),
     ForAll(
     MyCollection,
     Patch(
     'ABC',
     Defaults('ABC'),
     {
     Title: ThisRecord.'Title'
     }
     )
     )
    )

    Please also confirm that you have no records with a blank title in the collection-

    This could be accomplished using something like, just prior to your Patch statement:

    RemoveIf(
     MyCollection,
     IsBlank(Title)
    )

     

  • venky232 Profile Picture
    on at

    its working ,thanks for your Support. 
    one question, when user click submit button twice ,same selected records patching twice in list

  • madlad Profile Picture
    2,637 Moderator on at

    that makes sense, as it's likely still selected- if the collection is only being used to patch to the SharePoint list, you could clear it after the patch statement runs, which should solve this.

     

    If you can't clear the collection quite yet, but  you never want to have duplicate records in the list, you could also include something like:

     

    If(
     !(ThisRecord.Title in 'ABC'.Title), 
     Patch(...)
    ) 

     

    in your ForAll, just to ensure duplicates don't patch.

  • venky232 Profile Picture
    on at

    again got some issue, here it checking duplicate record only 1st item, if i going to patching mutiple records.

    RemoveIf(MyCollection, IsBlank('Title'))

    If(!IsEmpty(MyCollection),
    ForAll(
    Filter(
    MyCollection,
    Not(ThisRecord.'Title' in LookUp('ABC', 'Created By'.Email = User().Email, Title))
    ),
    Patch('ABC', Defaults('ABC'), { Title: ThisRecord.'Title' })
    )
    )

  • madlad Profile Picture
    2,637 Moderator on at

    If I understand correctly, your records are only being compared against the user's first record when patching?

    I think the problem lies in the:

    Filter(
     MyCollection,
     Not(ThisRecord.'Title' in LookUp('ABC', 'Created By'.Email = User().Email, Title))
    )

    LookUp only returns the first value it finds, so it will only compare your values to the first one created by the user. Try switching the code snippet above to something like:

    Filter(
     MyCollection,
     Not(ThisRecord.'Title' in Filter('ABC', 'Created By'.Email = User().Email).Title)
    )

    Please note I haven't tested this code so you may have to play around with it a little bit. 

  • venky232 Profile Picture
    on at

    its working now, thanks for Support

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