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

Community site session details

Session Id : SZZz7OfSG6ZaxsCOx3oiDi
Power Apps - Building Power Apps
Answered

Patch Function is not Working properly for Update in Powerapps

Like (0) ShareShare
ReportReport
Posted on 1 May 2023 05:47:14 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.

 

I have the same question (0)
  • STS_Senthu Profile Picture
    54 on 01 May 2023 at 07:09:01
    Re: Patch Function is not Working properly for Update in Powerapps

    Cheers mate. Thanks a million @WarrenBelz .

    Everything thing is working fine.

  • WarrenBelz Profile Picture
    149,740 Most Valuable Professional on 01 May 2023 at 06:48:52
    Re: Patch Function is not Working properly for Update in Powerapps

    @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 01 May 2023 at 06:46:32
    Re: Patch Function is not Working properly for Update in Powerapps

    Thanks @WarrenBelz .

     

    But what is 

    As aCol

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

  • Verified answer
    WarrenBelz Profile Picture
    149,740 Most Valuable Professional on 01 May 2023 at 06:40:40
    Re: Patch Function is not Working properly for Update in Powerapps

    @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

     

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 733 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 532 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 399 Super User 2025 Season 2

Last 30 days Overall leaderboard
Loading complete