Flex Repeater - Output param in view not matching instances array

Issue is on a form that contains a flex repeater where the repeated view is a dynamic number of rows containing a text string, checkbox, and comment field. It is possible to save and reload the form so the checkbox is sometimes checked by the user and sometimes checked by a startup script that sets the props.selected value to the saved value.

The repeated view has an input parameter Value used to set the initial value for the checkbox and an output parameter CurrentSelection bound to Checkbox.props.selected. The startup works in that if Value is set to True the checkbox will appear checked and if I then log the value of current selection it shows as true.

A script on the main form iterates through the flex repeater instances array after a save button is clicked and reads CurrentSelection for each instance. However the script will only read CurrentSelection as being true if the checkbox was checked by clicking on it - if it was set by the startup script it will read the initial default value set in the instances array (which I set to -999).

Version is 8.1.1. I saw people had similar issues on earlier versions, I tried upgrading a test environment to 8.1.7 but this did not resolve the issue.

How is the initial value written to the component? Iā€™m betting thereā€™s a race condition where the initial value code is the last to run and hence overwriting the script that sets it to the saved value

The initial value is set by creating a new instances array for the flex repeater in the script that reloads the form and setting the ā€˜Valueā€™ parameter in each.

Nothing should be setting the Value parameter after initialization and only the CheckboxRow startup script should be pushing the Value parameter to the props.selected of the checkbox.

I put a log message of the ā€˜CurrentSelectionā€™ output parameter that is bound (unidirectional) to props.selected at the end of the startup script after a 2 second sleep and it always matches the initial Value parameter. However when ā€˜CurrentSelectionā€™ is read by looking for CheckboxFlexRepeater.props.instances[ā€œCurrentSelectionā€] it does not match the logged value

I had this exact issue. The only way I found to solve it was by actually setting it to the correct value :confused: it's a bit horrible.. I posted about it, can't remember if I got any hits at the time. But the expressions in my instances that used my initial values didnt seem to always re-evaluate from the initial value I'd set. It would maybe 70% of the time

1 Like

Inductive support analyzed the code, the following fix was found to clear the issue.:

-When setting the instances array of the flex repeater always clear it first by setting it to []
-Create the new instances in an array and then set instances to the new array. Do not call the add method on the instances array directly.

1 Like

I had a similar issue, more to do with reevaluation of repeated view output params. After realizing it wasn't quite the same, I made a separate post: Output Param in Flex Repeater Missing

After figuring out my problem, I'm back to explain why clearing the instances array works.

As you mentioned, you're setting the value of instances by updating it in a script.
The interesting behavior arises because if you overwrite the output params of an instance, but don't change the input params enough to recompute the output params' bindings, the output params will not regenerate.

By first clearing the entire instances array, you're destroying the instances first, such that new ones, when instantiated by your script, compute all their outputs, as the instance is new and had no prior value.

I did find that clearing the instances array within the same script that sets its new value was not reliable for me, and I had to do something different to preserve the outputs and only update the input params I wanted instead of recreating the instances array.