cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
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
secondImage

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

Top Kudoed Authors
Users online (70,555)