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

Update all Items from a Gallery on button Click

Hi,

 

I'm trying to build a button that will cancel an order and return all the stock that was booked out on the order back to the stock available column.

 

I have this work if the user returns each item using the below:

UpdateIf('Resource Centre Inventory v5', ID = ThisItem.ProductID, {StockAvailability: LookUp('Resource Centre Inventory v5',ID = ThisItem.ProductID).StockAvailability + ThisItem.QTY})

 

But i can't work out how to change the above to loop through all items in a gallery and return stock.  I've tried swapping the ThisItem.production to Gallery_5.Selected but obviously this only does the first item/selected. I tried adding the order into a collection but i can't seem to match the ID with the master database Resource Centre Inventory. 

 

Any help would be really great.


Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @mousman85 ,

Try inserting these two pieces to replace what is there

ForAll(
   Gallery5_1.AllItems as aPatch,
   Patch(
      'Resource Centre Inventory v5',
      {ID:aPatch.ID},
      {
         StockAvailability: 
         aPatch.QTY + 
         LookUp(
            'Resource Centre Inventory v5', 
            ID = aPatch.ID
         ).StockAvailability
      }
   )
);
ForAll(
   Gallery5_1.AllItems as aDel, 
   RemoveIf(
      'RC Ordered Items', 
      OrderID = aDel.ID
   )
);

 

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.

View solution in original post

18 REPLIES 18
ArchitectMadhan
Responsive Resident
Responsive Resident

Please try with the Collection, You need to have the Product ID also stored in the collection. When a new item is added in the Order grid the same has to go to Collection, Likewise when order is loaded or opened, on the screen load you need to store the grid values to the Collection by clearing it. By doing so, you will always have the Collection with latest order related products in it.

 

If you find my solution helpful for resolving the issue, then please consider Accept it as the solution to help the other members find it more quickly.

I tried to add the order items in to a table: 

set(colItemsOrdered, gallery5_1.allitems)

 But when  i tried to match the colItemsorder.ProductID with the ID in inverntory management, i get an error on using = that says it can't compare a Number to a table?

Ramole
Memorable Member
Memorable Member

hi @mousman85 

 

Try this please 

 

 

Remove(CartList,ThisItem);UpdateIf(
    ProductServiceList,
    Title =ThisItem.SKU,
    {'Quantity On Hand': 'Quantity On Hand'   +  Value(DDAmountCart.Selected.Value)}
)

Please change to your data source and control names

 

Capture11.JPG

 

 

 

 

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."

Hi,

I have this working for items so the remove sits within the gallery that is fine. But what i need is one overall button that cancels the entire order that doesn't sit within the gallery. So i don't think the above will work for what I need as I can't reference an ThisItem as its not in the gallery. Below is my page layout, the cancal order button is where i have the issue, it can delete everything and return stock but it only returns the first item in Gallery 5_1.:

image.png

Ramole
Memorable Member
Memorable Member

Hi @mousman85 

Do you want to remove and return stock, already saved data ?

Do you need to delete all its in the gallery and return to stock or One by one ?

 

 

 

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."
KvB1
Solution Specialist
Solution Specialist

So what you need is a ForAll( to grab the the ProductID from the ordered item gallery, and using that as input to restock the inventory?

PaulD1
Super User
Super User

Be careful using UpdateIf, I believe it is non-delegable so your logic to update your quantity onhand will fail if the relevant row is not within the first 500 to 2000 (depending on the value of delegation limit in settings).

Also be wary that if your loop fails mid way through processing your data (or only finds/updates some records because of delegation issues), your data could be left in an inconsistent state (e.g. some but not all of records  get updated). This is where the value of transactions and stored procedures comes in with SQL (you can ensure that either the complete 'set' of updates succeeds or none of them do) but given the additional licensing costs of using Power Apps with SQL, you may be willing to accept that risk.

Ramole
Memorable Member
Memorable Member

Hi @mousman85 

 

Try this please as this code will delete all item in the gallery 

 

 

 

ForAll(Gallery14.AllItems,
    Remove('IT Equipment Orders', LookUp('IT Equipment Orders', ID= Value(  lblID.Text))))

 

 

Captureid.PNG

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."

I need to remove and return the stock that's already saved. I have a button to be able to return one by one if the user needs. 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,927)