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 / Patch to Sharepoint no...
Power Apps
Answered

Patch to Sharepoint not competing before I perform ClearCollect in next statement

(0) ShareShare
ReportReport
Posted on by 38

Hi

 

I am patching a Sharepoint list with records that have changed and then performing a ClearCollect to get the whole list back. I have sometimes had an issue where it has patched to Sharepoint but is not in my Collection.

 

Is it performing the ClearCollect before Sharepoint has finished Patching? 

 

 

 

 

// Patch Planned lines to SharePoint
ForAll (
 Filter(
 colPlannedLines,
 State = "Updated" || State = "New"
 ),
 Patch(
 Planned,
 Defaults(Planned),
 {
 MonthCommencing: locMonthCommencing,
 Person: {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
 Claims: Person.Claims,
 Department: "",
 DisplayName: Person.DisplayName,
 Email: Person.Email,
 JobTitle: "",
 Picture: ""
 },
 Project: {
 '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
 Id: Project.Id,
 Value: Project.Value
 },
 PlannedDays: PlannedDays
 }
 )
);
//Get current months Planned Hours
ClearCollect(
 colPlannedLines,
 Filter(
 Planned,
 (MonthCommencing = locMonthCommencing)
 ),
 "ID",
 "MonthCommencing",
 "Person",
 "Project",
 "PlannedDays"
);

 

Categories:
  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @brown_1892 If all that you want is to add the new record to your collection, just patch it in the collection as well rather than getting the whole list again. This will be more performant and also help to avoid the issue you are having.

  • brown_1892 Profile Picture
    38 on at

    Hi, sorry I cut out some of the code, I'm doing an Update if it exists or an Insert if it is New

    // Patch Planned lines to SharePoint
    ForAll (
     Filter(
     colPlannedLines,
     Not IsBlank(Person.Claims) And (State = "Updated" || State = "New")
     ),
     Patch(
     Planned,
     // Is this a new line
     If(
     State = "New",
     // This is a new line so use defaults
     Defaults(Planned),
     // Else, this is an exisiting line so patch (update) to SharePoint
     {ID: ID}
     ),
     {
     MonthCommencing: locMonthCommencing,
     Person: {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
     Claims: Person.Claims,
     Department: "",
     DisplayName: Person.DisplayName,
     Email: Person.Email,
     JobTitle: "",
     Picture: ""
     },
     Project: {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
     Id: Project.Id,
     Value: Project.Value
     }
     PlannedDays: PlannedDays
     }
     )
    );
    
    
    //Get current months Planned Hours
    ClearCollect(
     colPlannedLines,
     Filter(
     Planned,
     (MonthCommencing = locMonthCommencing)
     ),
     "ID",
     "MonthCommencing",
     "Person",
     "Project",
     "PlannedDays"
    );

     

     

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @brown_1892 You can do the same update/patch to your collection as well!

  • brown_1892 Profile Picture
    38 on at

    Hi, in my collection I have a dummy ID for 'new' records and I am trying to get the real ID back from Sharepoint and this is the reason why I'm doing the ClearCollect. Are you saying that I don't need to do this and if so how do I get the real Sharepoint ID to use in my App going forward?

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @brown_1892 The return value of Patch is the record that you modified or created. You can use this to update/patch your collection.

  • brown_1892 Profile Picture
    38 on at

    Hi, thanks for all your help on this. Where in my code would I need to add the new Patch to my collection 

  • CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @brown_1892 It would be better to store the record returned by the Patch in a variable and than use it in the Patch to the collection. You could do it in the same place where your ClearCollect is now.

  • brown_1892 Profile Picture
    38 on at

    Hi, my Patch is in a For All loop, am I still able to store the record in a variable?

  • Verified answer
    CNT Profile Picture
    10,921 Super User 2024 Season 1 on at

    @brown_1892 You can do it by using the With statement.

    ForAll(Filter(...),

         With({varPatchedRecord:Patch(SPList,.......)},

             Patch(collection...)

    ))

  • brown_1892 Profile Picture
    38 on at

    This has worked. Thank you so much!

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 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard