cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rknight
Helper II
Helper II

ForAll, Patch, LookUp issue with LookUp in a Collection

I am creating an inventory tracker. I have a SharePoint list with the inventories that are in a gallery with a checkbox next to each item. The user selects which items they would like to update, hits update, and a collection (checkedItems) is made with all of the items that were checked. The user then puts in how many they would like to Add or Take, and that number is used to alter the SharePoint list's item quantity. Screenshots are below.

 

The issue I am having is that the formula in the LookUp function is just not working. I can't seem to find the right syntax to compare the datasource's item IDs to the collection's to find the right record to Patch. Here is my code for the Add button:

 

ForAll(checkedItems,Patch('Inventory Tracking - TESTING',LookUp('Inventory Tracking - TESTING',ID=checkedItems.ID),{Quantity:Quantity+TextInput2_3})) ; Set(_popup,false) ; Set(isChecked,false) ; Set(isChecked,true) ; Clear(checkedItems)

 

**Screen 1

rknight_0-1614629153997.png

 

**Collection of checked items

rknight_1-1614629174740.png

 

**Add button in context of app

rknight_2-1614629235695.png

 

Any thoughts are welcome!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@rknight 

You don't need a checked collection for this...you already have one - the Gallery!

Please consider changing your Formula to the following:

Patch('Inventory Tracking - TESTING',
    ForAll(
        Filter(yourGallery.AllItems, yourCheckBox.Value) As _item,
        {ID: _item.ID,        
         Quantity: _item.Quantity + Value(TextInput2_3.Text)
        }
    )
); 
Set(_popup,false); 
Set(isChecked,false); 
Set(isChecked,true); 

Substitute the name of your Gallery and checkbox in the gallery in the above formula.

 

 I hope this is helpful for you.

_____________________________________________________________________________________
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

5 REPLIES 5
RandyHayes
Super User
Super User

@rknight 

You don't need a checked collection for this...you already have one - the Gallery!

Please consider changing your Formula to the following:

Patch('Inventory Tracking - TESTING',
    ForAll(
        Filter(yourGallery.AllItems, yourCheckBox.Value) As _item,
        {ID: _item.ID,        
         Quantity: _item.Quantity + Value(TextInput2_3.Text)
        }
    )
); 
Set(_popup,false); 
Set(isChecked,false); 
Set(isChecked,true); 

Substitute the name of your Gallery and checkbox in the gallery in the above formula.

 

 I hope this is helpful for you.

_____________________________________________________________________________________
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!
rknight
Helper II
Helper II

You are a wizard! Worked flawlessly! Thank you so much!

Another question. Say I wanted to put the Add and Take buttons on the main gallery screen and the update button on the pop up window. I tried roughly the same code, but now its updating every item checked with the first text input box value.

 

If(_addPressed=true,Patch('Inventory Tracking - TESTING',
ForAll(
Filter(Gallery2.AllItems, Checkbox2.Value) As _item,
{ID: _item.ID,
Quantity: _item.Quantity + Value(TextInput2_3.Text)
}
)
),Patch('Inventory Tracking - TESTING',
ForAll(
Filter(Gallery2.AllItems, Checkbox2.Value) As _item,
{ID: _item.ID,
Quantity: _item.Quantity - Value(TextInput2_3.Text)
}
)
)) ;

 

Any thoughts?

RandyHayes
Super User
Super User

@rknight 

The pressed property is only while the button is pressed (i.e. clicked) it will not maintain that state.

You need to look at another control, like a checkbox or a toggle to maintain the state of the press.  You can make a toggle look like a button and act like a "pressed - true" or "not pressed - false" control.

ToggleButton.gif

 

Secret sauce:

1) Add a Checkbox control

2) Set the Checkbox Size to 0

3) Set the Fill to :  If(Self.Value, Blue, LightBlue)  (choose your own colors)

4) Set the HoverFill to : Self.Fill

5) Set the HoverColor to: Self.Color

6) Set the Color to: If(Self.Value, White, Black)

 

NOW...you have another toggle in your gallery and you can use that in your formula:

 

Patch('Inventory Tracking - TESTING',
    ForAll(
        Filter(Gallery2.AllItems, Checkbox2.Value) As _item,
        {ID: _item.ID,
         Quantity: _item.Quantity + 
            (Value(TextInput2_3.Text) * If(yourNewToggleButton.Value, 1, -1))
        }
    )
)

 

_____________________________________________________________________________________
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!

I don't think I was very clear in my second question. 

I want to swap the positions of the Add & Take buttons and the Update button. 

The user will check the boxes of items he/she wants to update, then selects Add or Take, depending on what they're doing. Then, they enter the values and hit update. Depending on what they hit first (Add or Take) adjusts the quantity as such. Screenshots are below.

 

rknight_2-1614648170268.png

rknight_3-1614648223477.png

It is updating both items with only the first text box. Not sure why.

 

Let me know your thoughts!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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