Hi Neil!
I’ve solved your problem. It was informative and useful for me.
You can see how it works here: http://howitisdone.info/arrayinsc.html
Now the solution itself.
First of all, I would recommend that you do a little optimization. This will give you a lot of advantages. The steps will be easier, the logic will be simpler, and it will be much easier for you, and there will be fewer potential errors. The optimization is that you create a record in the "Fees"
table at the same time as you create a record in the first table (let it be the "Report"
table). in Other words, this is done in a single server action:
- first created an entry in the
"Report"
table;
- then created a record in the
"Fees"
table and linked it to a record from the "Report"
table (you can leave the field values empty).
This optimization will remove unnecessary logic from your step, which you are discussing here. You don’t have to create a condition where you choose to insert/update a record. You will just always update the entries, because they are already created.
I want to emphasize that this optimization is not mandatory. You can work with complex logic. But optimization will give advantages.
Now to the key questions. Namely, the correct transfer of the array from the form to the server action.
To begin with, let me explain about the record
array that you use in your examples. This array is created automatically whenever a repeat
is used in a server action. You can use it in General, but I will create a separate array so that you and other users can better understand the logic of interaction.
In the server action, the first step is to create an array (I called it rec
) and create variables inside it with the same name as the inputs in our form:
Now I will add an optional action. However, it will help you very much in diagnosing whether everything is going well. In the server action, insert the Set Value
step, which will be an array with the data source from the previously created rec array. Its task is to return the correct array to us. The settings look like this:
Now let’s turn to our form and its inputs. The names of inputs must match the names of variables in the rec
array in the server action that we created earlier:

And most importantly. Each input must have an additional name enabled via a dynamic attribute with the following value:

As you can see, the expression contains the name of the array (it must match the name in the server action), followed by the dynamic index, and then the name of the input.
Great. Let’s check the work. If everything is done correctly, we will get the correct array from our server action:
If you have achieved this, then 90% of the work is done. It remains to add a repeat
to the server action with the record update action. And since the data is now coming in correctly, we can configure Output Fields
in the repeat
:
Now in the update action we can select the correct data from the repeat
:
Done! 