Preventing infinite loop when updating/reverting embedded table view value

Hello,

I am running up against an issue where I have a table populated by a database query with several columns. One column I am rendering as a toggle and performing an update query on commit and it seems happy enough. But I didnt like the having to click to start cell commit (slightly clunky when using just a toggle) so like all programmers with a God complex (I created this one screen world, I will change anything to be how I wish) I created a view with a toggle, added the table params like value, row, column, etc., and rendered it in my table column using viewPath. Then I bind the input param 'value' to the toggle 'selected' and on render it looks right and the single click to change looks nice and smooth. I then have a changeScript on the 'selected' value on the toggle which tries to perform the update query.

The problem occurs if I need to revert the toggle value to its pre-user clicked value (say the update query fails). I can make logic to update the selected value back to the original (pre click) value, but then that triggers the changeScript and an infinite loop. I tried to do some debounce actions by adding a custom view property that would set to false when user clicks and then if the update succeeds back to true or after revert sets back to true, but it didn't seem to work. After trying this a few times the loop caused my gateway to crash and restart.

Because this doesn't happen with the vanilla table rendered boolean toggle using the edit commit I'm using it for now, but I was curious is anyone out there tried something similar and found a way around it. I'll admit I got stuck in an infinite loop myself for a while trying to figure it out :grinning_face_with_smiling_eyes:

IA threw an origin value into the changeScript that tells you the context the change was made from. Nesting your script in an if block that checks origin == 'Browser' should fix this issue for you.

Welcome to the forum, jj.

Tip: use paragraph breaks to break up your wall of text!