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 Function is not ...
Power Apps
Answered

Patch Function is not Working properly for Update in Powerapps

(0) ShareShare
ReportReport
Posted on by 54

 

Hai Everyone,

 

   I had completed this project apart from update functionality is not working properly. Before it worked fine but now it's is wrongly updating if i edit multiple record also finally patch is updating for only one id.

 

My requirement is i have a one combo box in that combo box multiple store name is added from connecting another sharepoint list. and i have a date picker so, i can select any date for any one store. 

 

Below that i am using a one gallery with add button 

 

 for that i am using one radio button and two textinput to add or update the record into a collection. after editing in gallery i am using a submit button to save in sharepoint list i will attach the every formula i am using. For New records it's working properly the problem is if edit mulitiple records means it's not working it is working for one item and it's is creating a dulicate records

 

I will attach the screenshot related to that. Please help out .client is pushing everyday

 

This is how my screen look like.

 

Screenshot 2023-05-01 110648.png  

 

Code for Edit Icon in Gallery.

 

Screenshot 2023-05-01 110854.png

For Delete code in gallery .

 

Screenshot 2023-05-01 111351.png

 

For Radio button Defaults code 

 

 

If(varNewEdit,Gallery1_36.Selected.Item_Type)

 

 

For Text input Defaults code 

 

 

 

If(varNewEdit,varDetails.Customer_Name,"")

 

 

For Add button Code

 

 

If(
 varNewEdit,
 Patch(
 colStoreLineDetail,
 Gallery1_36.Selected,
 {
 Customer_Name: TextInput1_85.Text,
 Deposit_Amount: Value(TextInput1_86.Text),
 Item_Type: Radio1_8.Selected.Value,
 Store_Email: User().Email,
 Store: ComboBox1_21.Selected.STORE_STOREId,
 Date: DatePicker1_10.SelectedDate,
 ItemType: If(
 IsBlank(Gallery1_36.Selected.ID),
 "New",
 "Edited"
 )
 }
 ),
 Collect(
 colStoreLineDetail,
 {
 Customer_Name: TextInput1_85.Text,
 Deposit_Amount: Value(TextInput1_86.Text),
 Item_Type: Radio1_8.Selected.Value,
 Store_Email: User().Email,
 Store: ComboBox1_21.Selected.STORE_STOREId,
 Date: DatePicker1_10.SelectedDate,
 ItemType: "New"
 }
 )
);
UpdateContext({varNewEdit: false});
Reset(Radio1_8);
Reset(TextInput1_85);
Reset(TextInput1_86);

 

 

Finally on Save button 

 

 

 ForAll(
 Filter(
 colStoreLineDetail,
 ItemType = "New"
 ),
 Patch(
 Dev_DSR_Line_Details,
 Defaults(Dev_DSR_Line_Details),
 {
 Customer_Name: ThisRecord.Customer_Name,
 Deposit_Amount: ThisRecord.Deposit_Amount,
 Store_Email: User().Email,
 Item_Type: ThisRecord.Item_Type,
 Date: DatePicker1_10.SelectedDate,
 Store: ComboBox1_21.Selected.STORE_STOREId
 }
 )
);
ForAll(
 Filter(
 colStoreLineDetail,
 ItemType = "Edited"
 ),
 Patch(
 Dev_DSR_Line_Details,
 LookUp(
 Dev_DSR_Line_Details,
 ID = Gallery1_36.Selected.ID
 ),
 {
 Customer_Name: ThisRecord.Customer_Name,
 Deposit_Amount: ThisRecord.Deposit_Amount,
 Store_Email: User().Email,
 Item_Type: ThisRecord.Item_Type,
 Date: DatePicker1_10.SelectedDate,
 Store: ComboBox1_21.Selected.STORE_STOREId
 }
 )
);

ForAll(
 Filter(
 colStoreLineDetail,
 ItemType = "Deleted"
 ),
 Remove(
 Dev_DSR_Line_Details,
 ThisRecord
 )
);
Clear(colStoreLineDetail)

 

 

On change of Combo box formula.

 

 

UpdateContext({varNewEdit: false});
ClearCollect(
 colStoreLineDetail,
 AddColumns(
 Filter(
 Dev_DSR_Line_Details,
 Store = Self.Selected.STORE_STOREId && Date = DatePicker1_10.SelectedDate
 ),
 "ItemType",
 "ToEdit"
 )
)

 

 

Thanks in advance.

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    155,640 Most Valuable Professional on at

    @STS_Senthu ,

    One of your issues lies with the edited patch - you are patching the same record with the entire collection - you need something like

    Patch(
     Dev_DSR_Line_Details,
     ForAll(
     Filter(
     colStoreLineDetail,
     ItemType = "Edited"
     ) As aCol,
     {
     ID: aCol.ID, 
     Customer_Name: aCol.Customer_Name,
     Deposit_Amount: aCol.Deposit_Amount,
     Store_Email: User().Email,
     Item_Type: aCol.Item_Type,
     Date: DatePicker1_10.SelectedDate,
     Store: ComboBox1_21.Selected.STORE_STOREId
     }
     )
    );

    ForAll() 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.

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • STS_Senthu Profile Picture
    54 on at

    Thanks @WarrenBelz .

     

    But what is 

    As aCol

    and what should i mention in patch function .As acol is an collection name.

  • WarrenBelz Profile Picture
    155,640 Most Valuable Professional on at

    @STS_Senthu ,

    It is simply the As function (above) reference - you can call it whatever you want - just use the same reference in the Patch fields.

  • STS_Senthu Profile Picture
    54 on at

    Cheers mate. Thanks a million @WarrenBelz .

    Everything thing is working fine.

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 426

#2
WarrenBelz Profile Picture

WarrenBelz 381 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 315 Super User 2026 Season 1

Last 30 days Overall leaderboard