cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mherman284
Level: Powered On

Editable combo box in gallery problem - OnChange event

I'm working on a design pattern to implement an editable table (updating any cell immediately adds a record to or updates a record in database). Besides an issue that I previously documented with the Drop Down control, it seems there is an issue as well with the combo box control. For now I was just testing an insert with Patch (inserting into a secondary table that holds the many records associated with the combo box selections). The OnChange event appears to cause an infinite loop. It also appears that the OnChange event fires when the screen first loads. I may try to implement the same solution as I did with the Drop Down control (enabling a timer to finish before loading DefaultSelections; If(timerend,ThisItem.'fieldname',"")). I also tried (with no success), writing to single field using Concat, and reading from the field using a Split. Again that might work if work on an action to kick off a timer, and using the timer finish event to occur before loading the default selections. @mrdang @WonderLaura 

 

Just using this code in the On Change event of a combo box creates an infinite loop

Patch('[dbo].[tblOpportunityTrackerTBDTo]'
,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
,{PPMOpportunityID:9739296,New_res_name:"Doe, John"} )

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Editable combo box in gallery problem - OnChange event

To break the loop add a variable to the OnSelect to track the user making the change and then use that variable in the OnChange to determine if the Patch() should run.

 

It would look something like this:

 

OnSelect: Set(gvOnChange, true)

 

OnChange: If(gvOnChange, Set(gvOnChange, false); Patch('[dbo].[tblOpportunityTrackerTBDTo]'
,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
,{PPMOpportunityID:9739296,New_res_name:"Doe, John"} ))



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

2 REPLIES 2
Highlighted
Super User
Super User

Re: Editable combo box in gallery problem - OnChange event

To break the loop add a variable to the OnSelect to track the user making the change and then use that variable in the OnChange to determine if the Patch() should run.

 

It would look something like this:

 

OnSelect: Set(gvOnChange, true)

 

OnChange: If(gvOnChange, Set(gvOnChange, false); Patch('[dbo].[tblOpportunityTrackerTBDTo]'
,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
,{PPMOpportunityID:9739296,New_res_name:"Doe, John"} ))



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

mherman284
Level: Powered On

Re: Editable combo box in gallery problem - OnChange event

Thanks, @Jeff_Thorpe . That worked. Of course, that was just the first step (I'm not always adding). I use a secondary table (id/new_res_name), to store the values of the combo box. The id value is another gallery column. I use the RemoveIf / For All in succession below, but the performance is sub-obtimal. When a user adds an additional selection in the combo box, the user sees all the values go blank for a moment, then reappear with the new selection. Maybe in the RemoveIf I should target a collection instead of a database table directly?

 

If(gvOnChange
,Set(gvOnChange, false);
ClearCollect(dtTBDTo,AddColumns(cboTBDTo.SelectedItems.New_res_name,"id",ThisItem.id));
RemoveIf('[dbo].[tblOpportunityTrackerTBDTo]',PPMOpportunityID=ThisItem.id);
ForAll(
dtTBDTo
,Patch('[dbo].[tblOpportunityTrackerTBDTo]'
,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
,{PPMOpportunityID:Value(id),New_res_name:New_res_name})
)
)

 

Helpful resources

Announcements
thirdimage

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors
Users online (6,148)