Get Exact Row-Id Number in table

I am trying to get exact row id (idx) through custom script. This is what I’m getting
console.log(cur_frm.doc.table_name[0].idx). But it is giving me everytime first row. How to get the latest row ??

Try this :slightly_smiling_face:

let table = cur_frm.doc.table_name;
console.log(table[table.length -1].idx)

Since you are specifying 0 index of table, that’s why it is showing the first row everytime.

Thats the index for parent doctype not child

What I was looking for, it gives me the exact same index I am working on. Let say I worked on 1st row and inserted data.
Then I added a row and same step for 2nd . But then if I entered some wrong value in row 1, it will still give me row 2. But I want there to be row 1.

In simple…exact row id where I’m working on

Index for parent would be frm.doc.idx and above it’s mentioned in frm.doc.table_name[0] which points to the first row of the table.
To get the current row idx, you can add a trigger on


in which you can get the current child doc and it’s idx.


This is triggering on Add rows . Let Say I Added till 2 rows and it shows idx as 2 which is fine. But when I re modifies value at row 1, It should be giving me row 1. But its giving row 2.

There’s a trigger of mine already in child table’s field as

//my code
So need to get the current (working/modified) idx here

You’ll have to play around with triggers. If it’s a specific field which you are checking in the table, try the below code snippet.

frappe.ui.form.on(“[Child_doctype_name]”, {
[child_doc_fieldname] : function(frm,cdt, cdn){
child_doc = frappe.get_doc(cdt,cdn);



1 Like