cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Jonfarmer4999
Level: Powered On

ForAll and Patch, Data Not Saving.

I am attempting to create a "Save All" facility on a gallery view. The user changes some data in multiple fields and then clicks save. 

 

This is what I have for the onSelect on the "Save All " button. 

 

ForAll(Gallery2.AllItems,Patch([@'Opportunity Lines'],First( Filter( [@'Opportunity Lines'], 'Opportunity Line ID' = 'Opportunity Lines'[@'Opportunity Line ID'])),{Quantity: Value(txtQuantity.Text),'Manual Discount Amount': Value(Replace(txtManualDiscount.Text,1,1,"")),PCOUpdateRequired: true}))

 

There are no errors when the function runs but the values in revert back to the previous value when you click the button. 

 

Any ideas what I am doing wrong?

 

Regards

Jon

7 REPLIES 7
Dual Super User
Dual Super User

Re: ForAll and Patch, Data Not Saving.

Hi @Jonfarmer4999 

 

Can you try to update this to:

ForAll(RenameColumns(Gallery2.AllItems,"Opportunity Line ID","Opportunity Line ID1"), Patch([@'Opportunity Lines'],First( Filter( [@'Opportunity Lines'], 'Opportunity Line ID' = "Opportunity Line ID1")),{Quantity: Value(txtQuantity.Text),'Manual Discount Amount': Value(Replace(txtManualDiscount.Text,1,"")),PCOUpdateRequired: true}))

 

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Jonfarmer4999
Level: Powered On

Re: ForAll and Patch, Data Not Saving.

@yashag2255 

 

Trying your formula I get two errors

 

The function RenameColumns has some invalid arguments 

 

The specified column "Opportunity Line ID" does not exist.

 

Dual Super User
Dual Super User

Re: ForAll and Patch, Data Not Saving.

Hey @Jonfarmer4999 

 

In that case, you can update the formula to:

ForAll(RenameColumns(Gallery2.AllItems,"opportunityproductid","opportunityproductid1"), Patch([@'Opportunity Lines'],LookUp( [@'Opportunity Lines'], opportunityproductid = opportunityproductid1),{Quantity: Value(txtQuantity.Text),'Manual Discount Amount': Value(Replace(txtManualDiscount.Text,1,1,"")),PCOUpdateRequired: true}))

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS! 

Jonfarmer4999
Level: Powered On

Re: ForAll and Patch, Data Not Saving.

Hi @yashag2255 

 

That seems to work, however there is a strange effect that after the first item in the gallery is saved the other items revert back to their previous values and then one by one they update and save.

 

Any way to stop the gallery updating while the save is in progress?

 

Regards

 

Jon

Community Support Team
Community Support Team

Re: ForAll and Patch, Data Not Saving.

Hi @Jonfarmer4999 ,

Do you want to prevent the Gallery from updating when the saving operation is in process?

 

Based on the needs that you mentioned, I think the collection could achieve your needs. Ono your side, you could consider save your 'Opportunity Lines' records into a collection firstly, then connect the Gallery to the collection rather than the original 'Opportunity Lines' data source.

 

I have made a test on my side, please consider take a try with the following workaround:

Set the OnStart property of App to following:

ClearCollect(OpportunityLinesCollection, [@'Opportunity Lines'])

Set the Items property of the Gallery to following:

OpportunityLinesCollection

the modify your ForAll formula as below:

ForAll(
       RenameColumns(Gallery2.AllItems, "opportunityproductid","opportunityproductid1"), 
       Patch(
              [@'Opportunity Lines'],
               LookUp( [@'Opportunity Lines'], opportunityproductid = opportunityproductid1), 
               {
                      Quantity: Value(txtQuantity.Text),
                     'Manual Discount Amount': Value(Replace(txtManualDiscount.Text,1,1,"")),
                      PCOUpdateRequired: true
               }
      )
);
Refresh([@'Opportunity Lines']);  // Refresh dta source 
ClearCollect(OpportunityLinesCollection, [@'Opportunity Lines'])  // Update the OpportunityLinesCollection from your 'Opportunity Lines' data source

Please consider take a try with above solution, then re-load your app (fire the OnStart proeprty of App), then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Jonfarmer4999
Level: Powered On

Re: ForAll and Patch, Data Not Saving.

Hi

 

I tried another method of hiding the Gallery before the save and replacing with a Saving message and then show the Gallery again when the save completes. Works well.

 

Regards

 

Jon

Community Support Team
Community Support Team

Re: ForAll and Patch, Data Not Saving.

Hi @Jonfarmer4999 ,

Have you solved your problem?

Have you taken a try with the solution I provided above?

 

I also agree with your solution almost. If you have solved your problem, please consider go ahead to click "Accept as Solution" to idenfity this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (6,219)