cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

How to stop Patch overwriting LookUp Column Values

Hey everyone,

 

So I've got 2 lists here,

SharePoint Picture Library: Auction Item Photos 
SharePoint List: Auction Items

 

In Auction Item Photos, I have a lookup column called Auction Item LookUp which looks up to the Auction Items list and grabs an auction item, essentially making it so that one photo can be re-used by multiple auction items.

 

VIP567_0-1631943684723.png

 

I'm trying to make it so that after the Admin creates an Auction Item, they can go in and select all the pictures they want associated with the created item. 

VIP567_3-1631943993263.png

VIP567_1-1631943835793.png


Once you click "Done" I want to loop through all the selected photos and add the selected Auction Item to the Auction Item LookUp column.

 

Currently with my code if I click "Done", it adds the items to the correct photos no problem.

VIP567_4-1631944232654.png

 

But once I select a different Item to add photos to, its replacing the previous values

VIP567_5-1631944290890.png

 

 

ClearCollect(
    AddImages,
    AuctionItemImageGallery_1.AllItems
);
RemoveIf(
    AddImages,
    Checkbox3.Value = false
);
ForAll(
    AddImages,
    Patch(
        'Auction Item Photos',
        {ID: ThisRecord.ID},
        {
            'Auction Item LookUp': Table(
                {Id: Gallery1.Selected.ID},
                {Value: Gallery1.Selected.Title}
            )
             
        }
    )
)

I believe it may be something to do with the ID I'm using but I've gone too deep, need another set of eyes 🙂 
Hopefully makes sense, will clarify if needed.

 

1 REPLY 1
WarrenBelz
Super User
Super User

Hi @Anonymous ,

It is everything to do with the ID and one of the many reasons you need to consider why you actually need to use Lookup columns (this would be very easy with a Text column) - but that is another discussion . . .

The ID (actually Id ) is the ID of the item looked up in the other list and you may not have this in the Gallery. Another issue is that the value you post must match the value of this field in the other list. Assuming that they do match, you would need to do something like this

With(
   {
      wImages:
      Filter(
         AuctionItemImageGallery_1.AllItems,
         Checkbox3.Value
      )
   },
   ForAll(
      wImages As aPatch,
      Patch(
         'Auction Item Photos',
         {ID: wImages.ID},
         {
            'Auction Item LookUp': 
            {
               Value: aPatch.Title,
               Id:
               LookUp(
                  'Action Items',
                  YourFieldLookedUpName = aPatch.Title
               ).ID
            }
         }
      )
   )
)

 

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 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 (1,706)