Visual Print Design Frappe

Hello everyone! I’m a Frappe student and I’ve encountered a problem in my study project. I need your help to solve this and also to share knowledge.

I’m trying to create a dynamic table using the Frappe’s visual print design in an environment where the item’s name is replaced by the item’s code. To achieve this, in the application, I created a link field and made a fetch that searches for the doctype Item and retrieves the description. However, when generating a report, the item appears with the code, which is correct, but I would like the ‘item’ field to display the item description instead of the code, due to the fetch.

“I tried to solve the problem using the Jinja2 API, but I didn’t succeed. Below, I’ll share how I tried to approach it, using the available resources, but I couldn’t find videos or tutorials that taught me how to use these methods. I would like to discover how I can solve this problem and find a way to make this index dynamic so that the formula I’m trying to apply in Jinja works for all rows.”

Now I’ll share the path I followed to create this table and the code I’m using in an attempt to rename the items. I tried to use a ‘for’ loop to capture all the items and then apply some condition or modification to them, but I didn’t succeed. Therefore, I need your help to solve this problem.

This is how I hope it appears:

{% set item_dinamico = doc.item_orcamento[0].estrutura %}
{% set item = frappe.get_doc(‘Item’, item_dinamico) %}
{{ item.descricao if item else ‘Item não encontrado’ }}

The code:

{% set count = 0 %}
{% for element in doc.item_orcamento %}
{% set count = count + 1 %}
{% endfor %}

{% for item_dinamico in doc.item_orcamento %}
{% set item = frappe.get_doc(‘Item’, item_dinamico.estrutura) %}
{{ item.descricao if item else ‘Item não encontrado’ }}
{% endfor %}

finish:

I needed a dynamic index, but I don’t know how to do it. ><

@marciio_junioor i would request you to see how print designer works as i don’t think you would need to use jinja for your use case. Incase, if you want to access row in table it’s {{ row.idx }}.