web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / ForAll, Patch, LookUp ...
Power Apps
Answered

ForAll, Patch, LookUp issue with LookUp in a Collection

(0) ShareShare
ReportReport
Posted on by 86

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!

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

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

  • rknight Profile Picture
    86 on at

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

  • rknight Profile Picture
    86 on at

    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 Profile Picture
    76,299 Super User 2024 Season 1 on at

    @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))
     }
     )
    )

     

  • rknight Profile Picture
    86 on at

    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!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 324 Most Valuable Professional

#2
11manish Profile Picture

11manish 193

#3
Valantis Profile Picture

Valantis 138

Last 30 days Overall leaderboard