cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JeffHe
Microsoft
Microsoft

COMBO BOX OnChange update with incorrect row value to collection

My app is a Power App canvas. I develop a combo box in a gallery. The Combo box data source is an API endpoint. I implement an Update formula in combo box OnChange. The Update formula should update the item data of the collection with the selected data id. When run the application, the first row is updated successfully. However, when second row added and combo box updated, the collection item of second row updated with the value of the first row. And the third and so on rows have the same issue.

The update formula is implemented as below, the issue is serviceTreeId is always set with first row combo box selected id. The expected behavior should be serviceTreeId is set with value of the combo box that user updated.

JeffHe_0-1653281035572.png

 

BTW, when I move the Update formula to OnSelect, the data update correctly. However, it has other issue, so it is not a perfect workaround.

1 ACCEPTED SOLUTION

Accepted Solutions
v-yujincui-msft
Community Support
Community Support

Hi @JeffHe ,

 

I have made a test with the Patch() function and it seems that works fine.

 

1. Here is my data source.

vyujincuimsft_0-1653470315642.png

2. Here is the data source for the Combo Box, which is a collection.

vyujincuimsft_1-1653470570755.png

3. Select the Combo Box Control and apply the following formula on its OnChange property as:

Patch(datasource,ThisItem,{serviceTreeId:ComboBox2.Selected.id})

vyujincuimsft_2-1653470679364.png

Result:

patch.gif

vyujincuimsft_3-1653470931755.png

 

 

Best Regards,
Charlie Choi

View solution in original post

11 REPLIES 11
JeffHe
Microsoft
Microsoft

Update one information: The Combo box data source is an API Endpoint.

v-yujincui-msft
Community Support
Community Support

Hi @JeffHe ,

 

I have made a test with the Patch() function and it seems that works fine.

 

1. Here is my data source.

vyujincuimsft_0-1653470315642.png

2. Here is the data source for the Combo Box, which is a collection.

vyujincuimsft_1-1653470570755.png

3. Select the Combo Box Control and apply the following formula on its OnChange property as:

Patch(datasource,ThisItem,{serviceTreeId:ComboBox2.Selected.id})

vyujincuimsft_2-1653470679364.png

Result:

patch.gif

vyujincuimsft_3-1653470931755.png

 

 

Best Regards,
Charlie Choi

JeffHe
Microsoft
Microsoft

Hi, @v-yujincui-msft , thank you for your reply. I tried your solution, I think you have not set  "defaultSelectedItems", so I removed the formula of "defaultSelectedItems". Although the collection updated, but the selected value didn't show on the combo box UI. Is there any solution for this?

v-yujincui-msft
Community Support
Community Support

Hi @JeffHe ,

 

Here is the configuration of my Combo Box Control. Hope it helps.

vyujincuimsft_0-1653532823627.png

 

 

Best Regards,
Charlie Choi

Hi, @v-yujincui-msft , thank you for sharing. So when Patch or Update used in OnChange, the selected item value didn't show in the combo box. We need to show the selected item in another component. Do my understand correct?

v-yujincui-msft
Community Support
Community Support

Hi @JeffHe ,

 

Sorry i am a little confused, could you please share a screenshot of the problem you encountered?

You could change the display text of the Combo Box by editing the Fileds property.

vyujincuimsft_0-1653535477066.png

 

 

Best Regards,
Charlie Choi

Hi @v-yujincui-msft , sorry for confusing. I mean I expect the selected item would be show like below. But actually it didn't show. Can I make it show?

JeffHe_0-1653536157539.png

 

v-yujincui-msft
Community Support
Community Support

Hi @JeffHe ,

 

Do you want the Combo Box Control to display the corresponding text by default based on the serviceTreeId of this record?

Maybe you could try to select the Combo Box and apply the formula on its DefaultSelectedItems property like this:

[LookUp(testcollection,ThisItem.serviceTreeId=id).value]

vyujincuimsft_0-1653542569579.png

 

 

Best Regards,

Charlie Choi

Hi, @v-yujincui-msft thank you! I confirm that when use collection as data source there is no problem. But my implementation uses API Endpoint as data source, so that user can search backend data by keyword. The "Items" and "defaultSelectedItems" are both get from API Endpoint. Is there anything I need take care when I use API Endpoint as data source?

 

JeffHe_0-1653547486338.png

 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,032)