cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver I
Resolver I

Gallery & Combobox OnChanged loop

Hi,

I have a gallery connected to an on-premise sql server datasource.

In the Gallery I have a combobox with its items source being another table in the sql database and, the default selected item being a lookup to the id of a field in the gallery.

This works, lists the items in the combo box, and shows the correct selected item for each record in the gallery.

The problem comes when I try to patch the sql table from the OnChanged property of the combobox.

I have the following e.g. on the OnChanged property of the combobox

Patch('SQL-Table', ThisItem, {MyFieldId:ComboBox.Selected.id})

Now, this also works and updates the table but then triggers a loop.

  1. OnSelect patches the table
  2. The change in the table triggers the gallery to reset
  3. All the fields in the gallery clear then set to the records of the table again
  4. The ComboBox sees the change from a selection to blank to selection and a change
  5. The ComboBox fires its OnChanged event
  6. The loop restarts

This loop continues until some timeout or loop counter internally to powerapps is reached then it stops.

No errors are shown but the gallery continues to reset and reload while the loop is in progress and no other controls in the gallery can be modified.

I have a feeling this is something to do with the delay in response to the datasource.

If I do the same to a collection, no loop occurs.

 

Any suggestions on how to stop it looping?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Hi @SimonMeadows ,

Could you please share a bit more about your scenario?

 

I have made a test on my side, and don't have the issue that you mentioned. As an alternative solution, you could consider take a try to save your SQL Table reocrds into a Collection within your app, then use the Collection as data source (instead of nature SQL Table data source) within your Gallery.

Then when you made changes within the Combo Box control, patch the changes into above Collection and your SQL Table data source at the same time.

 

I have made a test on my side, please take a try with the following workaround:

Set the OnStart property of the App control or OnVisible property of the first screen to following:

ClearCollect(
                    RecordsCollection,
                    'SQL-Table'
)

Set the Items property of the Gallery to following:

RecordsCollection

Within the Gallery, set the OnChange property of the Combo Box control to following:

Concurrent(
Patch( /* <-- Patch changes to Collection */ RecordsCollection, ThisItem, { MyFieldId: ComboBox.Selected.id } ), Patch( /* <-- Patch changes to your SQL Table */ 'SQL-Table', LookUp('SQL-Table', PrimaryColumn = ThisItem.PrimaryColumn), /* <-- PrimaryColumn represents the Primary Key Column in your SQL Table */ { MyFieldId: ComboBox.Selected.id } )
)

More details about the Concurrent() function, please check the following article:

Concurrent function

 

Please take a try with above solution, then check if your issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Highlighted
Community Support
Community Support

Hi @SimonMeadows ,

Could you please share a bit more about your scenario?

 

I have made a test on my side, and don't have the issue that you mentioned. As an alternative solution, you could consider take a try to save your SQL Table reocrds into a Collection within your app, then use the Collection as data source (instead of nature SQL Table data source) within your Gallery.

Then when you made changes within the Combo Box control, patch the changes into above Collection and your SQL Table data source at the same time.

 

I have made a test on my side, please take a try with the following workaround:

Set the OnStart property of the App control or OnVisible property of the first screen to following:

ClearCollect(
                    RecordsCollection,
                    'SQL-Table'
)

Set the Items property of the Gallery to following:

RecordsCollection

Within the Gallery, set the OnChange property of the Combo Box control to following:

Concurrent(
Patch( /* <-- Patch changes to Collection */ RecordsCollection, ThisItem, { MyFieldId: ComboBox.Selected.id } ), Patch( /* <-- Patch changes to your SQL Table */ 'SQL-Table', LookUp('SQL-Table', PrimaryColumn = ThisItem.PrimaryColumn), /* <-- PrimaryColumn represents the Primary Key Column in your SQL Table */ { MyFieldId: ComboBox.Selected.id } )
)

More details about the Concurrent() function, please check the following article:

Concurrent function

 

Please take a try with above solution, then check if your issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted

Hi @v-xida-msft 

 

I was hoping not to have to use galleries and re-collect them all the time but it seems that is the way to do it.

 

I do still have the looping issue and have uploaded a video to illustrate:

https://sway.office.com/kg00JPyvJmul3qZv?ref=Link

My SQL Tables are:

'[dbo].[Trips]',
{
id: string (GUID primary key),
Description: string,
Start: datetime,
End: datetime
Driver: string (GUID foreign key to drivers table)
}

'[dbo].[Drivers]',
{
id: string (GuUID primary key),
Name: string,
Email: string
}

The gallery items is set to

'[dbo].[Trips]'

The Combobox in the gallery

Items: '[dbo].[Drivers]',
DisplayFields: ["Name"],
DefaultSelectedItems: LookUp('[dbo].[Drivers]',id=ThisItem.Driver),
IsSearchable: false,
SelectMultiple: false,
OnChange: Patch('[dbo].[Trips]', ThisItem, {Driver:ComboBox3.Selected.id})

On closer inspection (and the video shows it) it appears to patch more than just the record I change, then continues to loop for a while on the last record. My guess is it's some kind of bug, or I'm doing something strange.

I'll mark your reply as the answer but it would be good to know what might be causing this behavior if you find anything.

If you want more info let me know.

Highlighted
Regular Visitor

It has been a while since this has been posted, but I am having the same issue when using the OnChange property on a Combobox in a Gallery, patching an (Azure) SQL Database. When the OnChange property fires, it patches all records in the table and gets stuck in a loop.

 

Alternative solutions are welcome!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,039)