cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
_sourcecod3_
Helper IV
Helper IV

Update item in collection from selected item in gallery.

Hi all,

 

I'm working on an inventory app and i need to be able to add , edit and remove items from a  collection as they're selected from a gallery. I'm getting stuck on updating a record in a collection, which in my scenario is the quantity of items selected from the gallery. Users should be able to click on the same items multiple times and those items will be added to the collection, then patched to a SharePoint list. When the items are added to the collection they show up on another gallery which the source is the collection. This is what I have so far on a button: 

If(
    varCount <= varCount,
    Set(
        varCount,
        varCount + 1
    );
    If(
        !IsBlank(
            LookUp(
                colProductSelected,
                itemID = mainGallery.Selected.ID
            )
        ),
        UpdateIf(
            colProductSelected,
            mainGallery.Selected.ID = itemID,
            {itemQTY: varCount}
        ),
        Collect(
            colProductSelected,
            {
                itemDescription: lbItemTitle.Text,
                itemStars: Value(lbRequiredStars.Text),
                itemQTY: varCount,
                itemID: Value(lbGalleryItemID.Text),
                itemGUID: varGUID
            }
        )
    )
)

 

My code adds the item to the collection. when you click on item1 it adds it to the collection and it shows the quantity of "1" in the quantity column of my second gallery, the problem is that when i click on item2 and gets added to the collection i can't go back and click on item1 to add it again. It adds a number to the last selected item not the current selection....

 

I know this is happening because of the 'Last' function on my code. What can i use instead so that it updates the selected item not the last selected one. 

 

Thanks in advance.

10 REPLIES 10

@_sourcecod3_ ,

So you changed to this?

If(
   !IsBlank(
       LookUp(
          colProductSelected,
          itemID = mainGallery.Selected.ID
      )
   ),
   UpdateContext(
      {
         varExists: true,
         varQTYCounter: varQTYCounter + 1
      }
   ),
   UpdateContext(
      {
         varExists: false,
         varQTYCounter: 1
      }
   )
);
If(
   varExists,
   UpdateIf(
      colProductSelected,
      itemID = mainGallery.Selected.ID,
      {itemQTY: varQTYCounter}
   ),
   Collect(
      colProductSelected,
      {
         itemDescription: lbItemTitle.Text,
         itemStars: Value(lbRequiredStars.Text),
         itemQTY: varQTYCounter,
         itemID: Value(lbGalleryItemID.Text),
         itemGUID: varGUID
      }
   )
)

Also put a couple of labels on the screen with varExists and varQTYCounter and see if they are the values you expect.

 

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.

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,649)