cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Spaceballs
Helper I
Helper I

Patch Existing Record & Add New Record from Collection to Sharepoint List

Hi,

 

I'm struggling coming up with a logic to check if the record exist in the SharePoint list against the Collection. 

If record existed in the Sharepoint then do not patch the record from the Collection 

If record does not exist then patch the record from the Collection to the SharePoint. 

 

Here is the patch function I created.

 

ForAll(Collection, 
        Patch(SharePointList, 
            Defaults(SharePointList),
        { 
            Control: Control,
            Name: Name,
            GUID: GUID
        }))

 

 

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @Spaceballs , 

Assuming you have the ID of the SharePoint list in your collection data

ForAll(
   Collection As aPatch,
   If(
      IsBlank(
         LookUp(
            SharePointList
            ID = aPatch.ID
         ).GUID
      ),
      Patch(
         SharePointList, 
         Defaults(SharePointList),
         { 
            Control: aPatch.Control,
            Name: aPatch.Name,
            GUID: aPatch.GUID
         }
      )
   )
)

If GUID is a unique identifier, you can also use that instead of ID.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

2 REPLIES 2
Ramole
Super User
Super User

@Spaceballs 
Similar question has been answered this post please have a look
https://powerusers.microsoft.com/t5/Building-Power-Apps/Patch-existing-records-and-add-new-records/m... 

Thank you
If this post helps, then Click on the Thumbs Up below. and Accept it as the solution . to help others find helpful.
WarrenBelz
Super User
Super User

Hi @Spaceballs , 

Assuming you have the ID of the SharePoint list in your collection data

ForAll(
   Collection As aPatch,
   If(
      IsBlank(
         LookUp(
            SharePointList
            ID = aPatch.ID
         ).GUID
      ),
      Patch(
         SharePointList, 
         Defaults(SharePointList),
         { 
            Control: aPatch.Control,
            Name: aPatch.Name,
            GUID: aPatch.GUID
         }
      )
   )
)

If GUID is a unique identifier, you can also use that instead of ID.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,005)