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

@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.
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 III
Super User III

@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.
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

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

@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.
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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,319)