Dynamic List Checkbox state on page load

In my app I have a table of warehouses and a table of companies. The users can add warehouses as relations to their companies as a 1toMany relation.
I have a page that is a dynamic list which is a toggle switch and the warehouse name (in the pic below i have changed this to objectId for privacy on the forum).

At the moment I have logic that when the toggle is switched on the warehouse is added to the users company as a relation, and conversely when they toggle it back it removes the warehouse as a relation, all good there.

But when you navigate away from the page the database stays upto date but if you come back to the page all the toggles are off even though there may still be relations between the company and the warehouse. I need a visual representation of what is in the database, so out of the list of available warehouses, which ones are already related to the users company as a child.
Normally for a toggle I would set the checked state to the page data property for the toggle but because its a dynamic list that isnt working.

So if I set the page data property “warehouseChild” as a list I can see that it pulls the related warehouses into the list on page load through the developer console of chrome.

Using the Checked State Logic of the toggle I’ve tried numerous thing to read the list in page data and check if it matches the container data then toggle the switch on page load. one such pitiful attempt is below.

That obviously doesn’t work because I’m not reading the list in page data which is what I am struggling with. Could anyone throw me a hint on this please? I’ve been through loads of tutorials now and I don’t remember coming across something like this.

App ID is 41F831D7-1082-9EE4-FF6C-0E7ED3481C00 if you need it.

Hello @Andrew_Billcliffe,

as I can see from the last picture, in the if-statement you are checking for equality a warehouseChild, which is an array (list), and a Container Item Data, which is an object.
Thus such a check will not work, since an object and array will never be the same.
You should check objects by keys, e.g. by objectId of an item.
I recommend you to use logs in order to debug what values are underhood each variable.


1 Like

Yes, the logs are very useful, i always forget about that option!