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 / Patch combo box items ...
Power Apps
Answered

Patch combo box items in gallery to multi-select lookup column of SP List

(0) ShareShare
ReportReport
Posted on by 12

Hi,

 

I’m new to Power Apps and I'd be really grateful for some help. I have a multi-select lookup column ('RelatedModels') in a Sharepoint list (‘Models’). I am pulling the items of this column into a combo box in a Power Apps gallery. The gallery’s DefaultSelectedItems are ‘ThisItem.RelatedModels.‘

 

I want to be able to update the combo box's selected items in the gallery, patch the items to a collection, which is a filtered version of my SP list, and finally patch the collection to my Models’ SharePoint list.

 

The OnSelect property of my button which is supposed to patch the updates to an existing item in my collection is:

 

ForAll(
 RelatedModels.SelectedItems,
 Collect(
 colItemsToPatch,
 {Id: ThisRecord.ID,
 Value:ThisRecord.Title}
 )
);
Patch(
 RelcolGridData,
 ThisItem,
 {RelatedModels:colItemsToPatch});
Clear(colItemsToPatch);

 

This works fine on the first OnSelect – all the items appear in the relevant column of the RelcolGridData collection. However, if I make further changes to the same items in the gallery's combo box, the items disappear after I have selected

the button which triggers the above formula. When I click on the table in the relevant item of the RelcolGridData collection, it contains the correct number of records, but most of the records are blank.

 

I hope this makes sense.

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Keleanorh 

    Unless there is a specific need for a collection, it is a bit overkill in this situation.

     

    Please consider changing your Formula to the following:

    Patch(Models
     ForAll(yourGallery.AllItems,
     {ID: ID,
     RelatedModels: 
     ForAll(yourCombobox.SelectedItems,
     {Id: ID,
     Value: Title
     }
     )
     }
     )
    )

    There are other dependencies that you might have changed or are different in your app that could impact this.

     

    I hope this is helpful for you.

  • Keleanorh Profile Picture
    12 on at

    Thanks for this and you're probably right that patching to a collection is overkill. A similar issue is happening with this formula though - the first time I click the button that runs the formula, the updates are patched to the list. However, if I go back and make another update to the same combo box, and run the formula again, the updates are not patched. Similar to my initial formula, it seems to sometimes loop through the items in the combo box and register blanks, even though items have been selected.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Keleanorh 

    Sorry...overlooked one thing.  The formula should be this:

    Patch(Models
     ForAll(yourGallery.AllItems As _item,
     {ID: _item.ID,
     RelatedModels: 
     ForAll(_item.yourCombobox.SelectedItems As _sel,
     {Id: _sel.ID,
     Value: _sel.Title
     }
     )
     }
     )
    )

    That should make sure everything is referenced properly.

     

    If it still is off, then we'll need to investigate the combobox properties a little further.

  • Verified answer
    Keleanorh Profile Picture
    12 on at

    After running that formula there was still an issue with the formula registering some blank values when looping through the combo box. As you suggested, I looked at the combo box's properties and realised that I had set the Items property to 'Models' and the DisplayFields and SearchFields were set to ['Title']. I changed the Items property to 'Choices([@Models]).RelatedModels)' and the DisplayFields and SearchFields then automatically changed to ['Value']. I therefore amended your formula by changing the the ID and Value of the combo box's records to 'Id'(previously 'ID') and Value (previously 'Title') and it worked fine.

    Patch(Models,ForAll([gallery name].AllItems As _item,{ID: _item.ID,RelatedModels: ForAll(_item.[combobox name].SelectedItems As _sel,{Id: _sel.Id,Value: _sel.Value})}))

     

    Thanks so much for your help. Changing Id and Value in my initial formula also worked but this formula has to be run on an item by item basis. Your formula suits my needs much better by looping through all the items in the gallery.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 223

Last 30 days Overall leaderboard