I have a custom print format which includes a child table with multiple rows.
I want to print only the last row.
how can I do that?
I have a custom print format which includes a child table with multiple rows.
I want to print only the last row.
how can I do that?
Did you find a solution to this? Iām also interested in achieving something similar
Cheers
I saw this topic when I really wanted to do exactly what you want and it took me around 3 days to got it done.
The solution is quite simple, just get the data you want from the database with this code in print format
{% set index = frappe.db.get_value('Sales Invoice Item', {'parent':doc.name}, 'idx', order_by="idx desc") %}
{{ index }}
In the code, I want to show the last row of index number in Sales Invoice Item which order_by=āidx descā will do the last row.
if you want multiple data to show you can put [āidxā,āitem_codeā,āitem_nameā] instead of āidxā
You can play around with the code to achieve what you want.
The syntax refers here
@wale This might help if you still need it.
Hi, you can solve this also just with jinja2 functions:
{% set last_item = doc.items|last %}
{{ doc.items|length }} - {{ last_item.item_code }} - {{ last_item.item_name }}
So you donāt need to make a database call.