cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
william_nr3
Frequent Visitor

For all Patch, only updating one record (collection part lookup)

I'm building an estimating app where the user can select accessory colors before converting the estimate to a contract. I have it set up where parts display in a gallery from a collection that gets created when the page loads. I am doing it this way so that qty, part numbers, cost, customer cost are persevered while material name, part number, and color can be updated by selecting a specific color.

 

Right now, it is functioning when the user goes through the gallery and clicks save on each item. I would like one button to update all the records however I am striking out. My patch only updates one record. Any guidance would be greatly appreciated!

 

gallery screenshot.png

DropDown to reference color options:

Items: Distinct(Filter(ColMaterials, Category = ThisItem.Category).Color,Color)

Default: ThisItem.Color


Save button: 

ForAll(Gallery8.AllItems,Patch(OrderLines,First(Filter(OrderLines,OrderIDRef=varOrderID&&Material=ThisItem.Material)),{Material:LookUp(ColMaterials,Category=ThisItem.Category&&Color=colordropdown.Selected.Result,'Material Name'),Color:colordropdown.Selected.Result,'Part Number':"test"}))

2 ACCEPTED SOLUTIONS

Accepted Solutions
RandyHayes
Super User
Super User

@william_nr3 

Yeah, first, your ForAll is backward - you're trying to use it as a For/Loop.  It's a table producing function.  When you use it like a for/loop, your performance will suffer.

 

Your Datasource in this case is the Gallery.  In your formula you are not making that the source and thus it is just referencing the first row.

 

Your formula should be this:

Patch(OrderLines,                
    ForAll(Gallery8.AllItems As _item,
        {cr1a5_id: _item.cr1a5_id,
         Material: _item.colordropdown.Selected.'Material Name',
         Color: _item.colordropdown.Selected.Result,
         'Part Number':"test"
        }
    )
)

 

Your colordropdown Items property should contain the data necessary for the Material or it should be coming from another source to avoid the Lookup you had - but I'm not clear on how you have that part of it.

The important part here is to include the ID primary key in your resultant table that you are submitting to Patch.  Patch will know what to do with it then.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

RandyHayes
Super User
Super User

@william_nr3 

Very good!!

Except you have an issue in that formula.  

It should be:

Patch(OrderLines,
    ForAll(Gallery8.AllItems As _item,
        {cr1a5_id: _item.cr1a5_id,
       Material: _item.timat.Text,
         Color: _item.colordropdown.Selected.Result,
         'Part Number':"test"
        }
    )
)

Having the extra gallery table in the Patch like that will cause issues.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

7 REPLIES 7
RandyHayes
Super User
Super User

@william_nr3 

What is your datasource you are using?

You should be working with the primary key of the data and also your ForAll is backward and being used as a For/Loop...which it's not.

Also you are referencing ThisItem...are you doing this in some control beside a button?

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hey Randy, thanks for the reply. I am using Dataverse as my data source for the gallery. I am using 'ThisItem' to reference the value that I want in the record.

RandyHayes
Super User
Super User

@william_nr3 

Sorry, didn't notice that the save button was in the gallery!!

But here is the thing - if you have a save button in the row, then the implication is that you are saving that row.  So then why would you be saving the whole gallery?

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

You are totally right. I started small with saving each record so that's why I have a save in each row. I would like to save the whole gallery. I took your guidance and have a save button outside of the gallery now + referencing the primary key. It runs but updates all the records in the gallery with the Material Name, Color, and Part Number from the first row. I'm not sure what I am missing.

 

ForAll(RenameColumns(OrderLines,"cr1a5_id","Custom_ID"),Patch(OrderLines,LookUp(Gallery8.AllItems,cr1a5_id=Custom_ID),{Material:LookUp(ColMaterials,Category=TextInput9.Text&&Color=colordropdown.Selected.Result,'Material Name'),Color:colordropdown.Selected.Result,'Part Number':"test"}))

RandyHayes
Super User
Super User

@william_nr3 

Yeah, first, your ForAll is backward - you're trying to use it as a For/Loop.  It's a table producing function.  When you use it like a for/loop, your performance will suffer.

 

Your Datasource in this case is the Gallery.  In your formula you are not making that the source and thus it is just referencing the first row.

 

Your formula should be this:

Patch(OrderLines,                
    ForAll(Gallery8.AllItems As _item,
        {cr1a5_id: _item.cr1a5_id,
         Material: _item.colordropdown.Selected.'Material Name',
         Color: _item.colordropdown.Selected.Result,
         'Part Number':"test"
        }
    )
)

 

Your colordropdown Items property should contain the data necessary for the Material or it should be coming from another source to avoid the Lookup you had - but I'm not clear on how you have that part of it.

The important part here is to include the ID primary key in your resultant table that you are submitting to Patch.  Patch will know what to do with it then.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Got it- thanks a ton. I got it working with the code below. I removed the lookup and put the lookup in the gallery itself (made it invisible). I may not be optimal, but the goal is for the user to change the color of the part and when they save it, it references the materials collection and updates the part in OrderLines with the appropriate name, color, and part number. The base quantity, customer price, and cost remain untouched. 

 

Patch(OrderLines, Gallery8.AllItems,
    ForAll(Gallery8.AllItems As _item,
        {cr1a5_id: _item.cr1a5_id,
       Material: _item.timat.Text,
         Color: _item.colordropdown.Selected.Result,
         'Part Number':"test"
        }
    )
)
RandyHayes
Super User
Super User

@william_nr3 

Very good!!

Except you have an issue in that formula.  

It should be:

Patch(OrderLines,
    ForAll(Gallery8.AllItems As _item,
        {cr1a5_id: _item.cr1a5_id,
       Material: _item.timat.Text,
         Color: _item.colordropdown.Selected.Result,
         'Part Number':"test"
        }
    )
)

Having the extra gallery table in the Patch like that will cause issues.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (4,207)