How to get last idx of child table


I have a custom doctype with custom child table. The child table is given as allow on submit, i have a function which will update child table rows on submit to Quotation doctype. After submitting the rows are getting added but if i again edit the row i need only the last row to get added in Quotation but the entire row is getting added. Kindly guide me how to get the last idx of child table in python script. I have used ,frappe.get_list(“Vendor RFQ Response Item”,filters={“parent”,“idx”:-1},fields=[“make_quote”,“idx”]).

In console only positive idx values are shown,


Need to know how to get last idx value.

Thanks in advance!

You can get last row by adding order by and limit args as mentioned below:
frappe.get_list("Vendor RFQ Response Item",filters={"parent":"VRSP-00060"},fields=["make_quote","idx"], order_by="idx desc", limit_page_length=1)


Thanks a lot, its working!



Do you know why when I input Jinja bracket my code stop working?

Exemple :
This work :
{{frappe.db.get_value('Purchase Receipt Item', {'parent': 'MAT-PRE-2022-00034','item_code': 'MHY-HE-CS-S'}, 'crop_type')}}

This doesn’t work :
{{frappe.db.get_value('Purchase Receipt Item', {'parent': '{{ doc.reference_name }}','item_code': '{{ doc.item }}'}, 'crop_type')}}

thank you for your help!

Remove single quote from outside bracket.

{{ doc.reference_name }}, 'item_code': {{ doc.item }}

When removing the bracket this error occur :

{{frappe.db.get_value('Purchase Receipt Item', {'parent': {{ doc.reference_name }},'item_code': {{ doc.item }}}, 'crop_type')}}
Traceback (most recent call last):
  File "apps/frappe/frappe/utils/", line 86, in render_template
    return get_jenv().from_string(template).render(context)
  File "env/lib/python3.7/site-packages/jinja2/", line 1092, in from_string
    return cls.from_code(self, self.compile(source), gs, None)
  File "env/lib/python3.7/site-packages/jinja2/", line 757, in compile
  File "env/lib/python3.7/site-packages/jinja2/", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "", line 1, in template
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'

Filter value should be without quotes and curly braces if not static

frappe.db.get_value('Purchase Receipt Item', {'parent': doc.reference_name,'item_code': doc.item }, 'crop_type')
1 Like

Wow thank you so much, it works :slight_smile: !

Now I would like to set this value into a custom field in Batch Doctype but it is not working :

frappe.ui.form.on('Batch', {
    refresh(frm) {
        var crp = frappe.db.get_value('Purchase Receipt Item', {'parent': doc.reference_name,'item_code': doc.item }, 'crop_type');
        frm.set_value('crop_type', crp);

Can you help me @sanjay ? :slight_smile:

Try below:

frappe.db.get_value('Purchase Receipt Item', {'parent': doc.reference_name, 'item_code': doc.item}, 'crop_type', (r) => {
	frm.set_value('crop_type', r.crop_type);