Looping through an array with accounts, but due to suffixes other arrays do not work

Hi,

I have several arrays (see below). In “account_array” I can have 1-8 accounts per key, separated by “;”. And in the “default_array” it lets the loop know if we should have “default:account.value” in our input, or if we should have “placeholder:0”.
The problem I have encountered is that if for example for key_001 and account 598000 have 598000.001, 598000.002 and 598000.003 etc then the loop does not understand that all of the 598000-accounts should have “default_array” value = “no”. It loops through the default_array and picks the value “no” for 598000.001, the value “no” for 598000.002 and the value “yes” for 598000.003.

How can I make the code understand that “no” should be applied by all the 598000-accounts? Below is part of the code, it is where the codes says “{% assign get_default = default_sub_array[forloop.index0] %}“ where I think things go wrong.

{% capture key_array %}key_001;key_002;key_003;key_004;key_005;key_006;key_007;key_008{% endcapture %}

{% capture account_array %}598000,599000,699300;607000,607100,607200,763100,763200;634000,634100,634200;642200,642300,655000,658000;698000,698100,698200;762200,762300;842300;509900,519900,690000,699200,769000,850000,860000,900000{% endcapture %}

{% capture default_array %}no,no,yes;no,no,yes,no,yes;no,no,yes;no,no,no,no;no,no,no;no,yes;yes;yes,yes,yes,yes,no,no,no,no{% endcapture %}

Part of the code:
{% for item in key_array %}
{% assign description_string = text_array[forloop.index0] %}
{% assign account_col = account_array[forloop.index0] %}
{% assign tot_accounts = period.accounts.include_zeros | range:account_array[forloop.index0] %}

| **{% t description_string %}** 

{% assign accounts_count = tot_accounts.count | integer %}
{% capture account_info %}{{ accounts_count }} {% t "konton" %}{% endcapture %}
| 
|
{% newline %}
{% assign default_sub_array = default_array[forloop.index0] %}
{% assign default_sub_array = default_sub_array | split:',' %}
{% capture result_name %}result_{{ description_string }}{% endcapture %}
{% for account in tot_accounts %}
  {% assign account_str = account.id %}
  |     {{ account.number }} {{ account.name }}
  | {{ account.value | currency:0 }}
    {% assign get_default = default_sub_array[forloop.index0] %}
   {% if get_default == 'yes' %}
    | {%=$2+input custom.dis_allowed.[account_str] as:currency precision:0 default:account.value assign:input_amount %}
  {% else %}
    | {%=$2+input custom.dis_allowed.[account_str] as:currency precision:0 placeholder:0 assign:input_amount %}
  {% endif %}
  {% assign sub_total_amount = sub_total_amount+input_amount %}
  {% rollforward nil custom.dis_allowed.[account_str] %}
  {% newline %}
{% endfor %}

Kind regards,
Anna

Hi @ahaegglund,

Before you can use the arrays, you need to split these and I currently don’t see the code you are using to do that. Could you please provide the full code? Otherwise try

{% assign key_array = key_array | split:";" %}
{% assign account_array = account_array | split:";" %}
{% assign default_array = default_array | split:";" %}

…which should be applied after defining but before iterating over the arrays.

Also keep in mind that forloop.index0 always follows the closest (inner) loop you are iterating over. default_sub_array[forloop.index0] therefore is defined as many times as there are accounts in tot_accounts (which can be many), while the default_sub_array has a couple of items in it at most (i.e. as much as there are yes/no statements under the current key). In your case, this may lead to a problem.

Does this help? Otherwise don’t hesitate to ask again.