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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Issue with Patch(Datas...
Power Apps
Answered

Issue with Patch(Datasource, Collection)

(0) ShareShare
ReportReport
Posted on by 54

Hi

 

I've been using a button with

Patch(
Activities;
Filter(
TempTblActivities;
Created <> Blank()
));;

 

to save changes done to multiple records back to a sharepoint list for quite a while now, but yesterday i ran into issues in the editor.

Suddenly the Patch would not fire any more in my current edit, so I checked the older published version and Patch seemed to work.

I restored that older version, opened it in the editor, but no, the Patch-function did not work. I published that version in case the problem only existed in the editor, but no, still didn't work. I've been messing around in the monitor to see what actually happens, but theres no data operation with patch.

 

I restored back to the older published version again, published it without the editor and now it works as published, but not in editor mode.

 

I all out of ideas. Maybe sharepoint changed? Maybe powerapps changed? The only difference between my current version of the app, and the one that worked earlier is that modern controls have replaced the old ones. 

 

 

Categories:
  • WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    Hi @aktuzad ,

    I am assuming 'TempTblActivities' is a collection ? If so for that structure to work every field in the collection needs to exist in both name and field type in Activities. Have you changed anything in either of them ? Also are you getting any errors in the code ?

  • aktuzad Profile Picture
    54 on at

    No errors.

     

    Yes, TempTblActivities is a collection. In Onvis, I first 

    ClearCollect(
    TblActivities;
    Filter(
    Activities;
    Name= User.Name
    ));;

    Then I ClearCollect(TempTblActivities;TblActivities);;

     

    There was a reason for the use of two similar collections, I believe it was necessary to have one to show data (TblActivities) and one to handle the changes locally (TempTblActivities), before patching to Sharepoint list (Activities).

  • Verified answer
    aktuzad Profile Picture
    54 on at

    @WarrenBelz 

    I've changed 

    Patch(
    Activities;
    Filter(
    TempTblActivities;
    Created <> Blank()
    ));;

    to

    ForAll(Filter(
    TempTblActivities;
    Created <> Blank());
    Patch(
    Activities;
    ThisRecord
    ));;

    which seems to be working. This would indicate that the collection; TempTblActivities, and the datasource, Activities, use the same field types and names, right? 

     

    I've been trying to follow guidance from Matther Devaney and Reza Dorrani, and allthough Patch(datasource,collection) might be "undocumented", its been working fine until recent. And like I mentioned, the current published app works, but when editing that version it does not work, and not when publishing that edit. Patch(datasource,collection) doesnt seem to fire any more. 

  • WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    @aktuzad ,

    Interesting as both codes are doing essentially the same thing, except ForAll is a bit more explicit. I have not struck the issue with the the collection direct and use it a bit myself in apps. You can also do this

    Collect(
     Activites,
     Filter(
     TempTblActivities;
     Created <> Blank()
     )
    );

    but that may not work if the Patch is not - so I suggest you stay with what you have.

  • aktuzad Profile Picture
    54 on at

    @WarrenBelz 

     

    How does this work?

    Collect(
     Activites,
     Filter(
     TempTblActivities;
     Created <> Blank()
     )
    );

     

    Seeing you have Created <> Blank() this would not create new items in the datasource, right? So you can use collect to "patch" changes to existing items?

     

    Ill keep trying to find the reason for this sudden change and will update this thread if so. 
    Thank you so much for your help so far, Warren!
     

  • StevenRichards Profile Picture
    164 on at

    One other way to write your formula that avoids writing to read only columns in SharePoint is to specify the columns you do have write access to:  (note the ID column is not optional. It replaces the filter you have on created <> Blank().

    Patch(
     SharepointList,
     ShowColumns(
     colSharepointList,
     ID,
     Title,
     Name,
     Place,
     Thing
     )
    );

     

  • WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    Hi @aktuzad ,

    It is just an alternative to Patch where you are sending all the records from TempTblActivities where the Created field is not blank to Activities. To be honest, I generally "future proof" my code (who knows what will be added / changed in the future) and Patch fields that could be changed explicitly - I assume you have the ID in the collection

    Patch(
     Activities;
     ForAll(
     Filter(
     TempTblActivities;
     Created <> Blank()
     ) As _Data;
     {
     ID: _Data.ID;
     FirstField: _Data.FirstField;
     SecondField: _Data.SecondField;
     . . . . . . .
     }
     )
    )

    I will offer some fundamental advice here that may assist with this and future ForAll() exercises. It is not designed to be a Loop, although it can work this way with considerable performance penalty as it does an individual Patch for each record. ForAll() creates a Table, which can be patched in one action provided its content is correct. For new records, this is simply a Table with field names and field types matching the list. For existing records, including the SharePoint record ID in the table causes it to update that record for each of the Table records.

     

  • MrGrumpyGuy Profile Picture
    4 on at

    I am having this exact same issue as of three days ago. Have been using Patch(List,Collection) as it is faster than ForAll(Patch( but now it is not working

  • WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    @MrGrumpyGuy ,

    I have found that has broken a few times before, hence I take the time to do explicit (and always reliable) patches.

  • MrGrumpyGuy Profile Picture
    4 on at

    This fixed my problem

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard