Open sashayar13 opened 3 weeks ago
{% set note_index = 0 %}
{% for item in ['hey', 'yo'] %}
{% set note_index = note_index + 1 %}
{{ item }}: {{ note_index }}: {{ loop.index0 }}: {{ loop.index }}
{% endfor %}
does demonstrate this issue. Looks like you can't update a variable in a loop in an easy way. What is the issue with loop.index
? Seems preferable to use something builtin rather than an additional variable. Is it because the index counter only increases for some of the records?
Here is an example of how it could be done:
{% set note_index = {"num": 0} %}
{% for item in ['hey', 'yo', 'more', 'items'] %}
{% if note_index.update({"num": note_index["num"] + 1}) %}{% endif %}
{{ item }}: {{ note_index["num"] }}
{% endfor %}
And here is using namespaces:
{% set note_index = namespace(num=0) %}
{% for item in ['hey', 'yo', 'more', 'items'] %}
{% set note_index.num = note_index.num + 1 %}
{{ item }}: {{ note_index.num }}
{% endfor %}
There is potentially a rendering issue with my markdown (see below).
I want to display the note_index sequentially for each item with notes. When this script is rendered it displays all notes with index = 1.
I've tried to apply it to the process model https://dev.app.spiff.status.im/editor/process-models/manage-finance:accounts-payable:process-expense-reports:capture-expense-data/files/capture-expense-details.bpmn Task - Review expense report. However, due to failure, I ended up using this script (which is not ideal). This script uses the item index for note_index.