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 / to reduce the patch fu...
Power Apps
Answered

to reduce the patch function code

(0) ShareShare
ReportReport
Posted on by 11

Hello there, 

In the save button, I'm using 4 Patch functions, 2 for new and updated actions in data source, and rest 2 for new and updated actions in collection. I have to repeat the codes 4 times. With this code, I can create new or update record successfully.

Max_Wang_0-1685946870599.png

Now, I try to reduce the code, to set the updated data into a variable, then replace the code with variable. But I got following error:

Max_Wang_1-1685947098583.png

Below is the variable data.

Max_Wang_2-1685947360010.png

Any idea to improved is appreciated. Thanks.

 

Max

Categories:
I have the same question (0)
  • Verified answer
    Ethan_009 Profile Picture
    4,838 Moderator on at

    Hi @Max_Wang ,

     

    You can update in your Collection then pass the collection to Patch function directly. 

    YouTube Link

    Note: If you are updating Items then you need to specific its Unique ID/GUID of the Records in collection.

     

    So your sequence will be

    //Create/Update Collection
    //Patch using Collection

     

    Hope this helps

  • Verified answer
    CU-18081211-6 Profile Picture
    9,272 Moderator on at

    @Max_Wang ,

    I suppose that your datasource (Requests) is a Sharepoint list and colRequests is a collection with a similar structure as Requests. Here is my proposal. 

    Patch(
     colRequests,
     Coalesce(LookUp(colRequests,ID=SampleGallery.Selected.ID),Defaults(colRequests)),
     Patch(
     Requests,
     Coalesce(LookUp(Requests,ID=SampleGallery.Selected.ID),Defaults(colRequests)),
     {
     item to be created / updated
     }
     )
    )

     Hope it helps !

  • Max_Wang Profile Picture
    11 on at

    Thank you both!

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 335 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 96 Super User 2026 Season 1

Last 30 days Overall leaderboard