cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Keleanorh
Frequent Visitor

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

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

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

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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
Super User
Super User

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

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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.

Helpful resources

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

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,068)