Show child table last row only in print format

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?

Hi @Ahmed_F_Mostafa

Did you find a solution to this? Iā€™m also interested in achieving something similar

Cheers

@Ahmed_F_Mostafa

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.

1 Like

@Manu5118

Thank a lot. Thatā€™s easier and it works perfectly.