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

Updating multiple SharePoint List records with ForAll and Patch - not working

Hey everyone!

 

Got an inventory app to track cables. What I have so far is a gallery of the SharePoint List with checkboxes next to each item. When the box is checked, it adds it to a collection called checkedItems. When the Update button is pressed, it bring up a pop up with another gallery showing the checkedItems collection. Then, the user can put in a number to add to or take from the inventory. 

 

However, when multiple items are checked, the SharePoint List does not update any item after the first one. Below are some screenshots. 

 

**Before Patch

rknight_0-1614381809421.png

 

**Add Inventory button with code

rknight_1-1614381890358.png

 

**Updated List (now it's adding the same value to only 2 items instead of the specified value for each item)

rknight_2-1614381989632.png

 

Any thoughts would be greatly appreciated! Best wishes!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@rknight 

Happy to help...we'll get this going!

 

Couple of clarifications and understandings:

1) User selects from main gallery (Gallery2) that they want to change the quantity of in inventory. They do this by checking the boxes next to each item they want. What is the name of the checkbox in Gallery2?

2) The User selects either Add or Take. This bring up the same popup window, but changes how the Update button behaves. This second gallery (Gallery7) shows them the color and length of the item they selected along with a textbox that they will enter a number into. This number will either increment or decrement the quantity of that specific item in the SharePoint list. Got it.

3) Once all info has been entered, the User hits the Update button, and it takes those values from the text boxes and increments or decrements the SharePoint list item's quantity by that number. Got it.

 

So what is Gallery 2 and Gallery1_1??  Or were they interjected erroneously into this thread?

 

So to revise based on the above and further clarity,

Your PopUp gallery (Gallery7) - Set the Items property to the following:

ForAll(
    Filter(Gallery2.AllItems, yourCheckBoxControlNameInGallery2.Value) As _item,
        {ID: _item.ID,
         Length: _item.Length, 
         Color: _item.Color,
         Quantity: _item.Quantity
        }
    )
)

Replace yourCheckBoxControlNameInGallery2 with the name of the checkbox control in your main gallery.

Replace Length above with the proper column name for Length (if it is not Length).

Replace Color above with the proper column name for Color (if it is not Color).

 

In the PopUp Gallery (Gallery7), your Color Name Label would be set to : ThisItem.Color

Your length label should be set to ThisItem.Length

 

And your Update OnSelect action property should be:

Patch('Inventory Tracking - TESTING',
    ForAll(
        Filter(Gallery7.AllItems, !IsBlank(TextInput2_3.Text)) As _item,
        {ID: _item.ID,
         Quantity: _item.Quantity + 
            (Value(_item.TextInput2_3.Text) * If(_addPressed, 1, -1))
        }
    )
);
Set(_addPressed, false);
Set(_takePressed, false);
Set(_popup, false);
Set(isChecked, false);
Set(isChecked, true)

 

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

13 REPLIES 13
HenryARPhillips
Continued Contributor
Continued Contributor

Hi,

 

It kind of looks like you are doing the right thing, in that you are doing a ForAll because you are working with multiple entries in a collection.

 

So for me it will be falling down on the, ThisRecord. For a test can you surface the SP List Item Id for each gallery entry and then in the Record of the Patch, replace the ThisRecord with a Patch('Inventory Tracking - TESTING',LookUp('Inventory Tracking - TESTING', Id = ***Value that will provide the Id of each List Item Id***), {Patch Values}) Just to see if it does anything different.

rknight
Helper II
Helper II

I can't figure out how to get this syntax to work. I keep getting an Invalid argument type error on the =. I know I need to get the ID value of the collection and compare it to the ID of the SharePoint list, but the syntax is eluding me.

rknight
Helper II
Helper II

Currently, this is what I have:

 

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)

 

Unfortunately, the ID=checkedItems.ID is erroring, telling me that the = is an invalid argument type. Not sure what to do here.

HenryARPhillips
Continued Contributor
Continued Contributor

Try something more along the lines of: ForAll(Gallery1_1.AllItems,Patch(CheckedItems,ThisRecord,{Quantity:ThisRecord.Quantity + TextInput1.Text})) ; Set(gblShowDialogue,false) ; Clear(colCheckedItems)

 

So Gallery1_1 has Items property set of colCheckedItems from the first gallery.

Unfortunately, I've gone away from using the collection. Is there a way to do this without referencing a collection?

HenryARPhillips
Continued Contributor
Continued Contributor

Just replace the collection with the gallery.AllItems?

RandyHayes
Super User III
Super User III

@rknight 

Trying to look around at your posts to make more sense on the other ones that we are working on.

 

So, this might answer my question in the other post.  You ARE bringing up another Gallery with those Red and Blue items in it.

By the way, your Gallery formula should be:

ForAll(
    Filter(Gallery1_1.AllItems, yourCheckBoxControlName.Value) As _item,
        {ID: _item.ID,
         Quantity: _item.Quantity + Value(_item.TextInput1.Text)
         Color: _item.SomeColorIndicator
        }
    )
)

I assume you only need the Color and Quantity (and ultimately the ID for the update) for your pop-up Gallery.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

I don't think I understand. Is that Gallery formula for the pop up window's gallery? Or is that for the Add/Take buttons? Or is that for the Update button? I just need the items checked to appear in the pop up gallery, then update the SharePoint list item's quantity. The issue is it's not pulling the numbers from the input boxes on the pop up window. It's only using one of two values to update both quantities. 

 

I apologize if I'm not making any sense and for all of the posts! ew to this whole PowerApps community thing 🙂

RandyHayes
Super User III
Super User III

@rknight 

The formula is a table formula and it is for the Items property of the Pop-Up gallery.  I assume that is what you were trying to accomplish in this post?

 

The Update and add/take buttons should all remain the same (well...we're working on that update formula in the other post).

In fact, based on what I am seeing in this post combined with the other post, your Update OnSelect formula should be:

Patch('Inventory Tracking - TESTING',
    ForAll(
        Filter(Gallery2.AllItems, Checkbox2.Value) As _item,
        {ID: _item.ID,
         Quantity: _item.Quantity + 
            (Value(_item.TextInput2_3.Text) * If(_addPressed, 1, -1))
        }
    )
);
Set(_addPressed, false);
Set(_takePressed, false);
Set(_popup, false);
Set(isChecked, false);
Set(isChecked, true)

 

So, for the Pop-Up gallery (in relooking at it) you have three bits of information - the Color, the current Qty and a textInput to indicate the amount to add or take (based on what button was pressed (or not pressed) prior to the popup). 

In that case we need four bits of information - the three above and the Record ID.

So, the Item property on the PopUp Gallery is based on the items that are clicked in the main gallery (assuming that to be Gallery1_1).

The formula would be:

ForAll(
    Filter(Gallery1_1.AllItems, yourCheckBoxControlName.Value) As _item,
        {ID: _item.ID,
         Quantity: _item.Quantity, 
         Color: _item.SomeColorIndicator
        }
    )
)

NOW...I don't know where you have TextInput1 and I am a little confused how this plays into the whole design.

 

My assumption on your design is that users will go through the main gallery and check the cables they want to change values on.  They then click on something that pops up the Gallery and buttons.

The gallery will show the items that were check and will have the color and the current quantity. And an empty TextInput control for them to enter the number of feet into.

They then click update and, based on the prior button they pressed (Add or Take) the update will either increment or decrement the items in the PopUp gallery (to the datasource) with the new quantity.

 

If all the above assumptions are correct, then what I am providing should give you what you need.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (30,933)