cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

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
Highlighted
Dual Super User III
Dual Super User III

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!

Highlighted
Helper III
Helper III

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.

 

Highlighted
Dual Super User III
Dual Super User III

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! 

Highlighted
Helper III
Helper III

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

Highlighted
Community Support
Community Support

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.
Highlighted
Helper III
Helper III

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

Highlighted
Community Support
Community Support

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
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (5,479)