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 / Combobox items propert...
Power Apps
Answered

Combobox items property is set to Distinct Single line of text Column - Cant patch the selected values to lookup column.

(0) ShareShare
ReportReport
Posted on by

Hi,

 

  • I have a Share Point List and it has a column called 'Component Name' which is a 'Single Line of Text' type column.
  • Within the same Share Point List I have another column called 'Connected Components' which is a lookup column which reads 'Component Name'. So I have the following;
  • PA_1.png
  • In Power Apps I have a Combobox and it's items property is set to 'Distinct('Share Point List', 'Component Name')'.  This combobox allows for multiple selections from the 'Component Name' column.
  • In Power Apps I then want to Patch the selected items in the combobox (all the Component Names) over to the column 'Connected Components'. I have the following in the OnSelect Property of a Submit Button;
  • Patch(
    'Share Point List',
    Defaults('Share Point List'),
    {
    'Connected Components': ComboBox.SelectedItems,
    }
    )

The above comes back with a network patching error and doesn't update the list. However, the above does work when the column being looked up is of type 'Choice' and I use Choices([@'Share Point List'].'Component Name') in the items property of the combobox. 

 

So I can patch combobox values of type choice to a lookup column, but I cant patch combobox values of type 'Single Line Text' to a lookup column.

 

Any help appreciated.

 

Thanks

 

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Marty3012,

     

    If I understand it correctly, the LookUp points to the same list? The issue is caused because a LookUp column expects a record to have the following structure:

    {
     Value: ,//Your primary column defined for the LookUp (Component Name)
     Id: //ID Column
    }

     

    The Following should do the trick 😊:

    Patch(
     'Share Point List',
     Defaults('Share Point List'),
     {
     //Map to the expected LookUp structure
     'Connected Components': ForAll(
     ComboBox.SelectedItems,
     {
     Value: ThisRecord.Value,
     //Fetch the ID of the first record matching the selected name
     Id: LookUp('Share Point List' As Inner, Inner.'Component Name' = Value).ID
     }
     )
     }
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • Marty3012 Profile Picture
    on at

    Hi @LaurensM , thanks for your reply.

     

    My Submit Button OnSelect property has the following code structure;

     

    Patch(
        'Share Point List',
        Defaults('Share Point List'),
        {
    //Numerous Fields are sent to Share Point List
        }
    );
     
    Patch(
        'Share Point List',
        Defaults('Share Point List'),
        {
            //Your own code to patch fields to lookup column
        }
    )
     
    So basically I am creating a new item in the Share Point List in the first Patch, with numerous fields sent over. In the second patch I am looking up that newly created item and using your code to Patch the combobox values over to the same list item using the Component Name as the reference. However, I get the following error;
    PA_2.png
    I did a separate Patch for your code within the same submit button as it looks up an existing item which is created in the first patch.
     
    Not sure where I'm going wrong.
     
    Thanks

     

  • Marty3012 Profile Picture
    on at

    Hi @LaurensM 

    Please ignore my last reply as I realised that I needed to make my Component Name column as 'Not Required' in the List settings. Once I did this I ran your code and it worked.

     

    However, after submission there are two items which are created in the list as I am using 2 patches in the same submit button onselect property. The first patch uses Defaults function to create the item and the second patch is meant to update the newly created item, but instead creates a new item. I realise why this is happening but I'm sure I need two separate patches to achieve my aim. I was thinking the 2nd patch would include the code which you provided but with the Defaults function removed and replaced with a lookup to the recently created item.

     

    Thanks

     

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Marty3012😊

     

    Patch with Defaults as second parameter will always create a new record. With your code example you will create 1 record with multiple SP column values and 1 with the LookUp collumn value. When wanting to update a record the second parameter will need to be a reference to the to-be-updated record. (LookUp, variable, Gallery.Selected... instead of Defaults) Additional information on using the Patch function can be found here

     

    Below I will create a structure in which you first create the record and then update that created record to add the LookUp value. However, I am not sure why you would like to use 2 patch statements instead of also supplying the LookUp value during the record creation - since the code runs within the same button OnSelect. Is there a specific reason why you would like to use 2 Patch() (create & update) statements instead of 1 create Patch where you supply all column values?

     

    2 Patch statements example:

    //With allows us to save a value as a function variable (only exists within the With function)
    //We will use the first Patch to store our record reference in the wRecord variable
    With(
     {
     wRecord: Patch(
     'Share Point List',
     Defaults('Share Point List'),
     {
     //Numerous Fields are sent to Share Point List
     }
     );
     },
     Patch(
     'Share Point List',
     //Here we reference the created record that we want to update
     wRecord,
     {
     //Your own code to patch fields to lookup column
     }
     )
    )

     

    I hope this helps!

  • Marty3012 Profile Picture
    on at

    Hi @LaurensM  - I thought I required 2 patches but that was just down to inexperience 😊.

     

    I've tried your code and it is almost working with the following parameters in the Update Patch;

     

    Patch(
         'Share Point List',
         wRecord,
         {
              'Connected Components': ForAll(
                   ComboBox.SelectedItems As aitem,
                   {
                        Value: aitem.Value,
                        Id: wRecord.ID
                        })
              }
         )
    );

     

    It creates the record and updates the lookup column but the value passed to the lookup column is the 'Component Name' rather than the selected values in the combobox. I have no idea why this is happening but maybe something to do with the id that is passed?. 

     

    Probably been looking at this too long and can't see the obvious 😊

     

    Thanks

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    @Marty3012 

     

    My apologies for the delay. 😊 Your patch code is very close!

     

    The issue is caused due to the Id mapping. The 'Value' is taken from the combobox loop, but the 'Id' references the created record. The Id column will need to be changed to a LookUp function - this function will search the first record in your list where 'Component Name' matches the selected combobox value.

     

    
    {
     Value: aitem.Value,
     //Search for the corresponding record matching our selected value & return the ID column
     Id: LookUp('Share Point List', 'Component Name' = aitem.Value, ID)
    }
    

     

    I hope this helps!

  • Marty3012 Profile Picture
    on at

    Great, that works!. Thanks for your help

  • LaurensM Profile Picture
    12,516 Moderator on at

    Perfect! Glad I was able to help. 😊

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 88

#2
WarrenBelz Profile Picture

WarrenBelz 85 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 45

Last 30 days Overall leaderboard