cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mherman284
Frequent Visitor

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
Jeff_Thorpe
Super User
Super User

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
Jeff_Thorpe
Super User
Super User

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

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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,488)