web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Combo Box issue after ...
Power Apps
Answered

Combo Box issue after patching

(0) ShareShare
ReportReport
Posted on by 36

I have a combo box shows a list of items from SQL: ItemA, ItemB ...(a list from a sql table), and a button for patching the data to SQL. 

MiaSunny_1-1710374542861.png

Patch( 'datasourceName',

  lookup( code for getting the cell), 

  {   columnNameInSQL: Concat( combox1.selecteditems, ",")

})

It works when I select something maybe ItemA and ItemB from the combo box, and click the button for submitting for the 1st time. 

MiaSunny_2-1710374583197.png( a label shows what is in SQL) 

And i set the DSI as: 

ComboBox1.DefaultselectedItems = split( dataInSQL, ",")

I could see the 2 items as selected. 

MiaSunny_3-1710374918167.png

But if I don't click anything in the combo box and click submit again, the result label shows nothing as selected, just a comma; ( count of comma = items selected last time -1, if the first time i select 3 items i will get only 2 commas). I think it should not change because it shows still the 2 items as selected.

 

Or if i add ItemC and submit, i get ",,ItemC" in SQL which is not as expected. 

MiaSunny_4-1710375039010.png

I am using a label to get the content submitted from the combo box, the text of it: 

concat( combobox1.selected.Items, ",") 

then i see only the 2commas and 3rd item. 

Wondering if my code not correct or this is an issue for combo boxes? 

Thank you ! 

Categories:
I have the same question (0)
  • wolenberg_ Profile Picture
    1,051 Moderator on at

    I think the use of Concat function it was the problem.... this function returns empty string if the table has no content to show, you can use before the concat an If statment,

    Like This:

    If(!IsBlank(combox1.selected.Items),concat( combobox1.selected.Items, ",") )

     

    This validation just fill the values if the combobox are not blank.

     

    If this comment help you someway, don't forget to Thumbs up ! 🙂

     

    Good luck!

     

  • v-jefferni Profile Picture
    on at

    Hi @MiaSunny ,

     

    Could you please share more details about your scenario? What's exactly the Items of this Combo box?

     

    Since you are using a SQL table as data source of the Combo box, it requires you use the column name (primary text) inside Concat function:

     

    Concat(ComboBox1.SelectedItems, ColumnName, ",")

     

     

    In DefaultSelectedItems property, it also requires a table with the same structure as in Items property. If you are using the entire table as data source:

     

    ForAll(Split(dataInSQL, ","), LookUp(SQLtable, ColumnName = ThisRecord.Value)).ColumnName

     

    Or

    RenameColumns(Split(dataInSQL, ","),"Value","ColumnName")

     

    Best regards,

  • MiaSunny Profile Picture
    36 on at

    Thank you, I have a validation when it writes to SQL, if combobox1.selecteditems is blank i will write a "None" into the cell, which works well. I didn't mention it since it's not the issue here. 

    And in this case I did select something -- ItemA and ItemB, and submit. then I am back again to add ItemC, but I lose ItemA and ItemB in the Combobox.SelectedItems, on the screen they look like selected, but from the code I just get commas and ItemC. 

  • MiaSunny Profile Picture
    36 on at

    Thank you for reading this. 

     

    Combobox1.Items = Sort ( 'SQLItemList', ColumnName, SortOrder.Ascending )

     

    In DSI: 

    Split(  LookUp(  'datasourcename',   ID=varCurrentID , ColumnName), ",") 

    which is also a table shows the selected items as rows; 

    I use clearcollect func to show it into a collection: 

    Clearcollect( colTest, Split(  LookUp(  'datasourcename',   ID=varCurrentID , ColumnName), ",") )

    MiaSunny_2-1710424625790.png

     

    But, for a second time i use the combobox, I add ItemC on, the collection is: 

    2 blank rows, and ItemC in the 3rd row with it's ID. 

    MiaSunny_1-1710424534104.png

    the third time it will be good again just like the first time, only odd times I get the issue. 

     

  • MiaSunny Profile Picture
    36 on at

    Hi @v-jefferni , I tried you code on DSI:

    ForAll(Split(dataInSQL, ","), LookUp(SQLtable, ColumnName = ThisRecord.Value)).ColumnName

    and it works -- it's a bit different from what I expected. 

    With this code, each time I submit something from the combo box with the btn, the combo box is reset. and it won't show what is selected last time. I suppose after u submit a form with several inputs, and when u review it in the next time, we could see the result in the combo box.  

  • v-jefferni Profile Picture
    on at

    Hi @MiaSunny ,

     

    Could you please share the Item property of the form and Patch function? If you are getting an item from and updating it using Patch to the same table, DSI of Combo box should always get the current value for you to review.

     

    Best regards,

  • MiaSunny Profile Picture
    36 on at

    Thank you for checking this, Jeffer!

    Item: 

    Combobox1.Item = Sort ( 'SQLItemList', ColumnName, SortOrder.Ascending )

  • Verified answer
    v-jefferni Profile Picture
    on at

    Hi @MiaSunny ,

     

    In DefaultSelectedItems property, keep in mind that it requires a child collection to the data source table in Items property. 

     

    For your testing, in LookUp function it needs to get items from Itemlists table.

    ForAll(Split(LookUp(Results, ID =1,ItemsSelected), ","), LookUp(Itemlists, Items = ThisRecord.Value))

     

    Besides, I see you are using the Patch function OnSelect of Combo box, it may cause issues because every time user taps the control it will update to data source. It's best to use formulas in the OnChange property.

     

    Best regards,

  • MiaSunny Profile Picture
    36 on at

    Thank you for the updates, Jeffer! 

    The code works with Patch since Patch is on the button not on the combo box. And I hope this could be helpful for others to know how to use combo box save and retrieve data. 

    And we tried to use UpdateIf instead of Patch which solved the problem. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard