User name in fori

I have a table containing a fori in the table there is a question and an answer under both fields shows the user who typed the text of the question or answer. However, if the text of the answer is saved, the user of the question also changes to the person who answered the question. What am I doing wrong in my code?

{% newline %}

{% fori vraag in custom.aanwezig_fisaal_review %}

{% capture fiscaal_antwoord %}{% t “Antwoord afwerking fiscale opmerking” count:forloop.index %}{% endcapture %}

|{{ forloop.index }}.

|{% input vraag.vraag as:text placeholder:“Fiscale opmerking” %}

|{% if vraag.vraag == empty %} {% input vraag.antwoord as:text placeholder:fiscaal_antwoord %} {% else %} {% input vraag.antwoord as:text placeholder:fiscaal_antwoord required:true %} {% endif %}

{% newline %}

|

|{::font size=“xs”} {% if vraag.vraag == emty %} {{ }} {% else %} {{ vraag.vraag.updated_by.name }}, {{ vraag.vraag.updated_at | date:"%d %B %Y"}}{% endif %} {:/font}

|{::font size=“xs”} {% if vraag.antwoord == emty %} {{ }} {% else %} {{ vraag.antwoord.updated_by.name }}, {{ vraag.antwoord.updated_at | date:"%d %B %Y"}}{% endif %} {:/font}

{% newline %}

{% endfori %}

{% endstripnewlines %}

Hi @donderdijk ,

The updated_at and updated_by statements in a custom collection work a bit differently than when applied to custom variables. They always return the latest update to any item of a specific iteration.

What I would advise to do is to only print (so not editable) the question when the answer field is completed. This way, you always know for sure that the latest update performed was to the answer field and therefore the update_at attribute refers to that specific field.

{% if vraag.antwoord == blank %}
  |{% input vraag.vraag as:text placeholder:“Fiscale opmerking” %}
{% else %}
 | {{ vraag.vraag }}
{% endif  %}

|{% if vraag.vraag == empty %}
   {% input vraag.antwoord as:text placeholder:fiscaal_antwoord %} 
 {% else %} 
   {% input vraag.antwoord as:text placeholder:fiscaal_antwoord required:true %} 
{% endif %}

Kind regards,

Michiel

I have included the suggested code. Now the text for question is only printed if the answer is also filled in. Both still have the same name and date underneath.


Voorbeeld 1

The code now looks like this

{% newline %}

{% fori vraag in custom.aanwezig_fisaal_review %}

{% capture fiscaal_antwoord %}{% t “Antwoord afwerking fiscale opmerking” count:forloop.index %}{% endcapture %}

|{{ forloop.index }}.

{% if vraag.antwoord == blank %}

|{% input vraag.vraag as:text placeholder:“Fiscale opmerking” %}

{% else %}

| {{ vraag.vraag }}

{% endif %}

|{% if vraag.vraag == empty %}

{% input vraag.antwoord as:text placeholder:fiscaal_antwoord %}

{% else %}

{% input vraag.antwoord as:text placeholder:fiscaal_antwoord required:true %}

{% endif %}

{% newline %}

|

|{::font size=“xs”} {% if vraag.vraag == emty %} {{ }} {% else %} {{ vraag.vraag.updated_by.name }}, {{ vraag.vraag.updated_at | date:"%d %B %Y"}}{% endif %} {:/font}

|{::font size=“xs”} {% if vraag.antwoord == emty %} {{ }} {% else %} {{ vraag.antwoord.updated_by.name }}, {{ vraag.antwoord.updated_at | date:"%d %B %Y"}}{% endif %} {:/font}

{% newline %}

{% endfori %}

{% endstripnewlines %}

Hi @donderdijk,

Please follow our standards to share your code as explained here.

As mentioned in the previous post, it’s not possible to get the timestamp of both your question and answer input fields, the timestamp will always be the most recent update to either your question or answer field.

That’s why I would suggest to only use this timestamp for the answer field. By ‘locking’ the question input field, we are sure that the updated_by method returns the latest update of the ‘answer’ field, as it is the only field editable for that specific iteration.

Kind regards,

Michiel