Fori in For Loop > duplicated values

Hi,

Could you please assist in below, each value of the input fields (in the fori) are duplicated if there’s a second value on the for loop. How can we resolve this:

{% for rekeningen2 in selected2 %}

{% stripnewlines %}
| {% t “Description” %}
| {{ period.minus_1y.year_end_date |date:’%d/%m/%Y’ }}
| {% t “InCo” %} ({% t “P&L” %})
| {% t “RePa” %}
| {{ period.year_end_date |date:’%d/%m/%Y’ }}
{% newline %}
|—40%-----
|:—15%-----:
|:—15%-----:
|:—15%-----:
|—15%-----:+
{% newline %}
| {{ rekeningen2.original_number }} {{ rekeningen2.original_name as:text }}
| {% assign valuepy2 = rekeningen2.opening_value as:currency %} {{ valuepy2 | currency }}
|
|
| {% assign valuecy2 = rekeningen2.value as:currency %} {{ valuecy2 | currency }}
{% capture reken_key %}reken_{{ rekeningen2.key }}{% endcapture %}
{% fori newitem in custom[reken_key] %}
{% newline %}
| {% input newitem.description2 as:text required:true placeholder:‘Description’ %}
| {% $4+input newitem.amount2 as:currency %}
| {% $5+input newitem.InCo2 as:currency %}
| {% $6+input newitem.RePa2 as:currency %}
| {% =$7+ newitem.amount2+newitem.InCo2+newitem.RePa2 as:currency %}
{% endfori %}
{% newline %}
| {% t “reconcile” %}
| {% unreconciled valuepy2-$4 as:indicator unreconciled_text:“Still to reconcile” %} {{ valuepy2-$4 | currency }}
|
|
| {% unreconciled valuecy2-$7 as:indicator unreconciled_text:“Still to reconcile” %}{{ valuecy2-$7 | currency }}
{% endstripnewlines %}

{% endfor %}

In your for loop, you are iterating over an accounts collection, which means you should use .id instead of .key:

{% capture reken_key %}reken_{{ rekeningen2.id }}{% endcapture %}

This will generate different names for [reken_key] each iteration, so the duplicates won’t show anymore.

Don’t hesitate to ask if you still encounter some problems!

Thank you !

Could you please assist in the following. In the post above we succeeded to use the fori loop.

But now we want show the collected info in a forloop see below:

{% for newitem in custom.[reken_key] %} {% if $1 != blank %}
{% newline %}
| {{ newitem.description2 }}
| -{{ newitem.InCo2 | currency }}
| {% input newitem.Ref as:text placeholder:“Notes” %}
| {% input newitem.Other as:file %}
{% endif %}
{% endfor %}

For one or other reason it shows only the two last records (3&4 and not the first and second), no clue why ?

Thx for assistance.

In order to answer your question, I would like to know how you defined [reken_key] before iterating over the collection.

Like in your initial post, first a capture statement like {% capture reken_key %}reken_{{ rekeningen2.id }}{% endcapture %} should be used to define the exact identity of the custom.[reken_key] collection you want to loop over.