Perspective FlexRepeater views not instantiating as expected

I have a Perspective page I want to use as a display / selection of equipment on a given line. I have a Flex Repeater and it is populated by the onStartup script.

The LineID is passed to the page’s params. When the onStartup event is triggered, the script reads the params.LineID and uses that to pull a list of matching equipment from a DB. I use a pre-built json string as the template for each view instance I want to create in the Flex Repeater, using .replace() to make the few changes each DB record brings, including view params. I then use <flexRepeater>.props.instances.append(jsonDecode(jsonTemplateString)) to load each instance into the Flex Repeater.

The view used for the Flex Repeater uses a similar pattern: The params were loaded into the Flex Repeaters props.Instances[x].EquipID, which is (should be?) pushed to the target view’s param.EquipID. Again, I use the onStartup event to read the view.params.EquipID and run a DB query to retrieve the relevent picture file name, description text, and status information.

This works perfectly…sometimes. About half the time, it works flawlessly. The other half, I do not get the same order, am generally missing one or two equipment pieces, and have one or two equipment pieces duplicated. There is always the correct count of views in the repeater, though.

I set up a logger to verify what the script in the Flex Repeater was building, and it matches the values in the DB. I set the Repeater’s target view to log the values it was seeing, which do not match what the Flex Repeater Built.
Below, the first line “Opening…” is the start of the main page onStartup event. The next string of “Created…” events are the creation and appending of the json strings. Finally, the “Opening…” events are the individual Flex Repeater views triggering their own onStartup events. In this example, I am missing EquipID “1” and “2”, and had duplicates of “11” and “12”.

I am not sure why this is occuring, but I suspect I am misunderstanding or misapplying something - maybe onStartup doesn’t guarantee the params values have been filled in before triggering?

Sun Jul 11 13:50:03 EDT 2021 : Opening Equipment list for line 2
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 1
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 2
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 3
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 4
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 5
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 6
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 7
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 8
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 9
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 10
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 11
Sun Jul 11 13:50:03 EDT 2021 : Created row for Line 2, Equip 12
Sun Jul 11 13:50:03 EDT 2021 : Opening Equipment row for equip 11
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 12
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 3
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 4
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 5
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 6
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 10
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 8
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 9
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 7
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 12
Sun Jul 11 13:50:04 EDT 2021 : Opening Equipment row for equip 11

I think this is your issue. From what I noticed, params are not guaranteed to be loaded before the startup script runs.
Here’s my post on the same issue:

I’m actually only just about to try this solution however as i’ve been flat out!

After some testing, I actually did find that the onStartup event did capture the params vals that had been passed in.

The part that was messing me up was using and output param in the View used in my Flex Repeater that was meant to update the row’s instanceStyle.display prop in order to hide or show the row based on other conditions for each row. In this scenario, I thought that my script to generate the instances object wasn’t firing properly as some rows that I expected to be visible were hidden.

To resolve it, when I was creating my instances array, I pre-populated the instance[x].instanceStyle.display props with the actual values, where before I was just setting this to hide the row and expecting that the binding would update it with the actual state, which didn’t happen for all rows…