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 / Patching a SharePoint ...
Power Apps
Answered

Patching a SharePoint list multi-select field overwriting instead of inserting

(0) ShareShare
ReportReport
Posted on by 8

Dear Community!

 

I'm having a hard time trying to update a SharePoint multi-select field, whatever I try overwrites the field instead of adding the selected new values.

So I have the first main list named Portfolio with a multi-select field (Execute) looking up values in a 2nd list named Learning Topics:

Alex69_0-1674461018133.png

I want to add new Learning Topics selected from a list box, but the following code I thought might've worked will overwrite the field instead of adding the newly selected learning topics:

//Fill fltColl with portfolio records to update

ClearCollect(fltColl,
Filter(Portfolio,Role in lstPersonaTo.SelectedItems && IndustryOrMarket.Id=cmbIndustryTo_2.Selected.ID && Domain.Id=cmbDomainTo.Selected.ID)); 

//Update the records

ForAll(
fltColl,Patch(Portfolio, LookUp(Portfolio, ID=fltColl[@ID]),
{
Execute:ForAll(lstLTs.SelectedItems,{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Id: ID,
Value: Title})
}
)
)

 

I tried different solutions but none of those worked. Can you help me out, please?

Thank You!

 

Categories:
  • WarrenBelz Profile Picture
    156,532 Most Valuable Professional on at

    Hi @Alex69 ,

    Firstly, I am relying on the Items of the Combo Box lstLTs to simply be the Choices of the Lookup field - if not this will be quite different, but try

    Patch(
     Portfolio,
     ForAll(
     fltColl As aPatch,
     {
     ID: aPatch.ID,
     Execute:
     ForAll(
     lstLTs.SelectedItems,
     {
     Id: ID,
     Value: Title
     }
     )
     }
     )
    )

    Also, I will offer some fundamental advice here that may assist with this and future ForAll() exercises. It is not designed to be a Loop, although it can work this way with considerable performance penalty as it does an individual Patch for each record. ForAll() creates a Table, which can be patched in one action provided its content is correct. For new records, this is simply a Table with field names and field types matching the list. For existing records, including the SharePoint record ID in the table causes it to update that record for each of the Table records.

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

  • Alex69 Profile Picture
    8 on at

    Thank You @WarrenBelz for taking the time to reply! 🙏🏻

    I tried the suggested code but I get the same result, the Execute field is overwritten with the newly selected items from lstLT list, and not adding those on top of the previous record content. So if I have "LT1", and "LT2" in the Execute field, and I select "LT3", and "LT4" from the lstLT control, the result is that the Execute field now holds {"LT3","LT4"}, instead of {"LT1","LT2","LT3","LT4"} as I need.

    Appreciate any help on this, I've been banging my head on the wall for 2 days! 😱

  • Verified answer
    victorcp Profile Picture
    2,350 Moderator on at

    Hi,

    It is a bit complex, but I will try to explain one way to do that, here is the code:

     

     

    ClearCollect(fltColl,
    Filter(Portfolio,Role in lstPersonaTo.SelectedItems && IndustryOrMarket.Id=cmbIndustryTo_2.Selected.ID && Domain.Id=cmbDomainTo.Selected.ID)); 
    
    // We need a collection to help on that I called it colAux
    Clear(colAux);
    ForAll(
     fltColl,
     With(
     {varItem: ThisRecord},
    
     // This loop will add all the existing values to the collection colAux
     ForAll(
     varItem.LookUpColumn,
     With(
     {varItemLookUp: ThisRecord},
     Collect(
     colAux,
     {
     itemID: varItem.ID,
     Id: varItemLookUp.Id,
     Value: varItemLookUp.Value
     }
     )
     )
     );
    
     // This loop will add all the new values to the collection colAux
     ForAll(
     ListBox1.SelectedItems,
     With({varListItem: ThisRecord},
     
     // This condition will check if the value already exist
     If(
     IsEmpty(Filter(colAux, itemID = varItem.ID && Id = varListItem.Id)),
     Collect(
     colAux,
     {
     itemID: varItem.ID,
     Id: varListItem.Id,
     Value: varListItem.Title
     }
     )
     )
     )
     );
    
     // And finally it will patch the new values
     Patch(
     Portfolio,
     varItem,
     {
     Execute: ShowColumns(Filter(colAux, itemID = varItem.ID),"Id","Value")
     }
     )
     )
    )

     

     

    So, what I did is creating a collection with all the existing and new values with a column to map the correct item (itemID column), and then Patched the item filtering the itemID column to get the correct values.

     

    I hope it helps 🙂

  • Alex69 Profile Picture
    8 on at

    You rock @victorcp! That worked out of the box!

    Great insight on how to get things done using a more iterative approach that for sure I'll keep in mind in the future!

    Great job man! 👍🏻

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 411 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 338

#3
WarrenBelz Profile Picture

WarrenBelz 256 Most Valuable Professional

Last 30 days Overall leaderboard